Angularjs Angular允许控制器在同一模块中协作
我有两个控制器,它们需要彼此的功能。这两个控制器位于同一个“控制器模块”中 我的问题是Angularjs Angular允许控制器在同一模块中协作,angularjs,Angularjs,我有两个控制器,它们需要彼此的功能。这两个控制器位于同一个“控制器模块”中 我的问题是函数A()内部控制器如何调用函数B()内部控制器B 希望有人能帮助我,它不应该使用服务或事件 请分享您的用例答案中的事件部分起到了作用。伟大的 angular.controller('a', [ '$scope', function ($scope) { $scope.$broadcast('something', 'with this', 'and this argument'); } ]
函数A()
内部控制器
如何调用函数B()
内部控制器B
希望有人能帮助我,它不应该使用服务或事件
请分享您的用例答案中的事件部分起到了作用。伟大的
angular.controller('a', [
'$scope',
function ($scope) {
$scope.$broadcast('something', 'with this', 'and this argument');
}
]);
angular.controller('b', [
'$scope',
function ($scope) {
$scope.$on('something', handleSomething);
function handleSomething () {
}
}
]);
angular.factory('a', [
function () {
return {}; // this is the API
}
]);
angular.controller('b', [
'a',
function (a) {
a.thing = 'value'; // methods would be preferrable.
}
]);
angular.controller('c', [
'a', '$log',
function (a, $log) {
$log.info(a.thing);
}
]);