$rootScope.$broadcast is used to broadcast a “global” event which can be caught by any listener of that particular scope. The descendant scopes can catch and handle this event by using $scope.$on.
$rootScope.$broadcast(name, args) $scope.$on(name, listener);
where listener specifies the function to call when the event is caught.
- Create a ParentController from which you would want to raise/broadcast an event.
- Use $rootScope.$broadcast in AngularJS to broadcast the event from the ParentController.
- Create a ChildController or an ExternalController (i.e., not a direct descendant of the ParentController) to catch and handle the event.
- Use $scope.$on in AngularJS to catch the respective event.
Example: This program uses $rootScope.$broadcast to raise an event using the approach discussed above.
- AngularJS and W3.CSS
- AngularJS | API
- AngularJS | Includes
- AngularJS | ng-src Directive
- AngularJS | ng-jq Directive
- AngularJS | Controllers
- AngularJS | How to use ng-idle?
- AngularJS | Directives
- AngularJS | ng-app Directive
- AngularJS | Tables
- AngularJS | Directive
- AngularJS | Forms
- AngularJS | Services
- AngularJS | HTML DOM
- AngularJS | Animations
- AngularJS | Routing
- AngularJS | Modules
- AngularJS | ng-value Directive
- AngularJS | ng-csp Directive
- AngularJS | Filters
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.