How to call a multiple controllers in single template in angularjs?

angular.module('test').controller('list', function($scope) {
    // Call entire test controller here
});

angular.module('test')
    .controller('getCustomers', function($scope) {
});

我需要实现这个功能才能访问其他控制器中的功能。


You can extend one controller to another by using the $controller service, something like:

angular.module('test')
    .controller('list', function($scope,$controller) {
        $controller('getCustomers', {$scope: $scope});
        $scope.getCustomersFn();
});
angular.module('test')
    .controller('getCustomers', function($scope) {
        $scope.getCustomersFn = function(){}
});

This is specially usefull if you want to create controller inheritance, but consider whether using a factory/provider is best suitable for your case, because it can be a bit hard to understand if you abuse it.

链接地址: http://www.djcxy.com/p/77570.html

上一篇: 两个控制器之间的angularJS应用程序中的条件属性

下一篇: 如何在angularjs中的单个模板中调用多个控制器?