0
兩個控制器結合如何將這兩個控制器結合成單一控制器類(使單個控制器類的兩個對象),以及如何使用相同的HTML如何angularjs
var firstController = function ($scope)
{
// Initialize the model variables
$scope.firstName = "John";
$scope.middleName = "Doe"
$scope.lastName = "Smith";
// Define utility functions
$scope.getFullName = function()
{
return $scope.firstName + " " + $scope.lastName;
};
};
var secondController = function ($scope)
{
// Initialize the model variables
$scope.firstName = "Bob";
$scope.middleName = "Al";
$scope.lastName = "Smith";
// Define utility functions
$scope.getFullName = function()
{
return $scope.firstName + " " + $scope.middleName + " " + $scope.lastName;
};
};
你爲什麼首先這樣做? – Alburkerk
實施服務/工廠。 – Hoyen