$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 | API
- AngularJS and W3.CSS
- AngularJS | Directive
- AngularJS | Routing
- AngularJS | Filters
- AngularJS | ng-csp Directive
- AngularJS | Modules
- AngularJS | Includes
- AngularJS | Controllers
- AngularJS | ng-jq Directive
- AngularJS | Events
- AngularJS | ng-app Directive
- AngularJS | HTML DOM
- AngularJS | Services
- AngularJS | Application
- Paging in AngularJS
- How AngularJS prefixes $ and $$ are used?
- AngularJS | ng-src Directive
- AngularJS | Animations
- AngularJS | Forms
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.