Understand the $on in Angularjs, $broadcast, $emit

Source: Internet
Author: User
Tags emit

$emit effect is to broadcast an event from a child scope to the parent scope until the root scope. (Including yourself)

$emit has two parameters name and Args,name are the names that need to be broadcast, and args is one or more parameters.

$broadcast parameters are the same as $emit, one is the name and the other is the parameter.

The $broadcast is for an event to be broadcast from the parent to the child scope. (Including yourself)

The same thing is: $emit, $broadcast need to bind events. Like this:

function () {$broadcast (broadcastname, Broadcastargs);}

The parent scope or child scope is then monitored for this event.

$on has two parameters, name and listener.

Name refers to the name of the event being monitored. For example, the above Broadcastname,listener is a function, it also has two parameters: event and args

The event has several properties:

Targetscope: Scope of propagation events

CurrentScope: Current Scope

Name: Event names, as EventName above

Stoppropagation (): Causes the $emit event to propagate no longer after the current scope is propagated

Preventdefault (): Prevents propagation of events and assigns a value of true to defaultprevented

Defaultprevented: Returns True if the Preventdefault event is called.

Understand the $on in Angularjs, $broadcast, $emit

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.