Skip to main content
deleted 1 character in body
Source Link
kyasar
  • 449
  • 5
  • 7

You must use $rootScope to send and capture events between controllers in same app. Inject $rootScope dependency to your controllers. Here is a working example.

app.controller('secondCtrl''firstCtrl', function($scope, $rootScope) { function firstCtrl($scope) { { $rootScope.$emit('someEvent', [1,2,3]); } } app.controller('secondCtrl', function($scope, $rootScope) { function secondCtrl($scope) { $rootScope.$on('someEvent', function(event, data) { console.log(data); }); } } 

Events linked into $scope object just work in the owner controller. Communication between controllers is done via $rootScope or Services.

You must use $rootScope to send and capture events between controllers in same app. Inject $rootScope dependency to your controllers. Here is a working example.

app.controller('secondCtrl', function($scope, $rootScope) { function firstCtrl($scope) { { $rootScope.$emit('someEvent', [1,2,3]); } } app.controller('secondCtrl', function($scope, $rootScope) { function secondCtrl($scope) { $rootScope.$on('someEvent', function(event, data) { console.log(data); }); } } 

Events linked into $scope object just work in the owner controller. Communication between controllers is done via $rootScope or Services.

You must use $rootScope to send and capture events between controllers in same app. Inject $rootScope dependency to your controllers. Here is a working example.

app.controller('firstCtrl', function($scope, $rootScope) { function firstCtrl($scope) { { $rootScope.$emit('someEvent', [1,2,3]); } } app.controller('secondCtrl', function($scope, $rootScope) { function secondCtrl($scope) { $rootScope.$on('someEvent', function(event, data) { console.log(data); }); } } 

Events linked into $scope object just work in the owner controller. Communication between controllers is done via $rootScope or Services.

Source Link
kyasar
  • 449
  • 5
  • 7

You must use $rootScope to send and capture events between controllers in same app. Inject $rootScope dependency to your controllers. Here is a working example.

app.controller('secondCtrl', function($scope, $rootScope) { function firstCtrl($scope) { { $rootScope.$emit('someEvent', [1,2,3]); } } app.controller('secondCtrl', function($scope, $rootScope) { function secondCtrl($scope) { $rootScope.$on('someEvent', function(event, data) { console.log(data); }); } } 

Events linked into $scope object just work in the owner controller. Communication between controllers is done via $rootScope or Services.