Trying to understand it is possible to communicate between Controllers under different modules. Is this even possible?
Here is my test that I am trying to learn from:
HTML
<div ng-app="app">
<div ng-controller="AppCtrl">
<p data-ng-bind="group.name"></p>
<p data-ng-bind="project.name"></p>
</div>
<div ng-controller="ProjectCtrl">
<p data-ng-bind="group.name"></p>
<p data-ng-bind="project.name"></p>
</div>
<div ng-controller="GroupCtrl">
<p data-ng-bind="group.name"></p>
<p data-ng-bind="project.name"></p>
</div>
</div>
javascript
var app = angular.module('app', ['project', 'group']);
var group = angular.module('group', ['project']);
var project = angular.module('project', ['group']);
app.controller('AppCtrl', ['$scope', 'Project', 'Group', function($scope, $project, $group) {
$scope.project = Project;
$scope.group = Group;
$scope.name = 'My App';
}]);
project.controller('ProjectCtrl', ['$scope', 'Project', 'Group', function($scope, $project, $group) {
$scope.project = Project;
$scope.group = Group;
$scope.name = 'My Project';
}]);
group.controller('GroupCtrl', ['$scope', 'Project', 'Group', function($scope, $project, $group) {
$scope.project = Project;
$scope.group = Group;
$scope.name = 'My Group';
}]);
Yes it is, using Broadcast or Emit. All controllers have access to a $rootScope. What you can do is broadcast a message to the rootscope, and then define $on methods on your other controllers. These in turn listen to events firing in the rootscope. Have a look at $broadcast in https://docs.angularjs.org/api/ng/type/ $rootScope.Scope and $on.
I think you are trying to re-use viewmodels and that's something I wouldn't do.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.