Event broadcast in Angularjs-comprehensive parsing $broadcast, $emit, $on _angularjs

Source: Internet
Author: User
Tags emit

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:

<! DOCTYPE html>  

Code

Effect:

Additional properties:

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.