如何将这两个控制器组合成单个控制器类(使单个控制器类的两个对象)以及如何在html中使用它们
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;
};
};
答案 0 :(得分:0)
您可以创建一个组件
angular.module('plunker').component('person',
{
templateUrl: 'person.html',
bindings: {
firstName: '<',
middleName: '<',
lastName: '<'
}
});
这是一个有效的插件: