Angularjs can be used to communicate between different scopes in a $broadcast, $emit, $on event broadcast mechanism
Introduced:
The role of $broadcast is to propagate events from the parent scope to the child scope, including itself. The format is as follows: $broadcast (Eventname,args)
The role of $emit is to propagate events from the child scope to the parent scope, including itself, up to the root scope. The format is as follows: $emit (Eventname,args)
$on is used to monitor events propagated from child or parent scopes in the scope and the corresponding data. The format is as follows: $on (Event,data)
In the above description, EventName is the name of the event that needs to be monitored, and the parameter event in the $on method is the object of the event, and data is the event-propagated information.
The event parameters in the $on method, like the following properties and methods
Event Property/Method Functional Description
Event Properties/Methods |
Functional Description |
Event.targetscope |
To get the scope of the propagation event |
Event.currentscope |
Gets the scope of the Receive event |
Event.name |
Name of the propagated event |
Event.stoppropagation () |
Block events from bubbling propagation, only valid in $emit events |
Event.preventdefault () |
Prevent propagation events from occurring |
event.defaultprevented |
Returns true if the Preventdefault event is invoked |
Code:
Code
Effect:
The above Angularjs in the event broadcast-comprehensive analysis $broadcast, $emit, $on is small to share all the content of the whole, hope to give you a reference, but also hope that we support the cloud habitat community.