The angular event system does not communicate with the browser's event system, which means that we can only listen for angular events instead of DOM events at the scope.
Angular event propagation: On a nested controller scope chain , it is possible to propagate down ($broadcast) and propagate up ($emit).
<div ng-controller= "Parentctrl" >//Parent <div ng-controller= "Selfctrl" >//Own <a ng-click= "click ()" > Click me</a> <div ng-controller= "Childctrl" ></div>//child </div> <div ng-controller= "Broc TRL "></div>//Peer </div>. Controller (' Selfctrl ', function ($scope) {$scope. click = function () {$scope. $broadcast (' to-child ', ' child '); $scope. $emit (' to-parent ', ' parent '); } }); . Controller (' Parentctrl ', function ($scope) {$scope. $on (' To-parent ', function (d,data) {console.log (data);//parent can get value}) ; $scope. $on (' To-child ', function (d,data) {console.log (data);//Sub-level not getting value}); }); . Controller (' Childctrl ', function ($scope) {$scope. $on (' To-child ', function (d,data) {console.log (data);//child can get value}); $scope. $on (' To-parent ', function (d,data) {console.log (data);//Parent not getting a value}); }); . Controller (' Broctrl ', function ($scope) {$scope. $on (' To-parent ', function (d,data) {console.log (data);//Not having a value on a peer}); $scope. $on (' To-child ', functiOn (d,data) {console.log (data);//No value on peer}); });
The value assigned by $broadcast can only be obtained by the child, and $emit assigned value can only be obtained by the parent, and nothing at the level can be obtained.
Angularjs Learning: Events