Angularjs Events $broadcast and $emit and $on
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8"> <title></title></Head><BodyNg-app= "Search"> <DivNg-controller= "Parentctrl"> <DivNg-controller= "Selfctrl"> <aclass= "BTN"Ng-click= "click ()">Click Me</a> <DivNg-controller= "Childctrl"></Div> </Div> <DivNg-controller= "Broctrl"></Div> </Div> <Scriptsrc= "Angular.min.js"></Script> <Script> varSearch=Angular.module ('Search', []). Controller ('Parentctrl', function($scope) {$scope. $on ('To-child', function(E, D) {Console.log ('It's my hair.')}) $scope. $on ('to-parent', function(E, D) {Console.log ('We are the parent, I got it', D)}) }). controller ('Selfctrl', function($scope) {$scope. Click= function() {$scope. $broadcast ('To-child', 'haha') //to Child$scope. $emit ('to-parent', 'hehe') //to the parent}}). controller ('Childctrl', function($scope) {$scope. $on ('To-child', function(E, D) {Console.log ('I\ ' The child, I got it', D)}) $scope. $on ('to-parent', function(E, D) {Console.log ('It's my hair.')}) . Controller ('Broctrl', function($scope) {$scope. $on ('To-child', function(E, D) {Console.log ('It's my hair.')}) $scope. $on ('to-parent', function(E, D) {Console.log ('It's my hair.') }) }) </Script></Body></HTML>
Angularjs Events $broadcast and $emit and $on