How can I send my $scope
object from one controller to another using .$emit
and .$on
methods?
function firstCtrl($scop
Scope(s) can be used to propagate, dispatch event to the scope children or parent.
$emit - propagates the event to parent. $broadcast - propagates the event to children. $on - method to listen the events, propagated by $emit and $broadcast.
example index.html:
Root(Parent) scope count: {{count}}
Childrent scope count: {{count}}
example app.js:
angular.module('appExample', [])
.controller('EventCtrl', ['$scope', function($scope) {
$scope.count = 0;
$scope.$on('MyEvent', function() {
$scope.count++;
});
}]);
Here u can test code: http://jsfiddle.net/zp6v0rut/41/