Sometimes we need to send data from one controller to another. There are services provided by AngularJS for communication(event-based) between the controllers. $on, $emit, $broadcast are the services for the communication between the controllers.
$on :- $on is used to catch the event dispatched by $broadcast and $emit. Basically it’s a method of scope and listens on events of a given type.
$broadcast : - $broadcast is the service that dispatches an event downwards to the child scopes. The life cycle of the event starts at the scope where the $broadcast is called. For example :-
- app.controller(“Eg1ctrl”, function ($scope) {
- $scope.$broadcast('eventName', { Tips: tip });
- });
Here is not the end…
Also visit Findnerd for such more interesting articles related to Javascript, Android, AngularJS etc.
No comments:
Post a Comment