The event of-angularjs-18-angularjs's life in Lei's dog

Source: Internet
Author: User
Tags emit event listener

For a front-end frame, it's easy to think about DOM events, such as mouse clicks and page scrolling, to bring up events. But what we're saying here is that the events and DOM events in angular are not a thing.

Publication of events

We can do this by $emit ()

and $broadcast () to publish the event

$emit (name, args)

Name of the event that is published
Args are passed to the listener of the event as an object
Events that are published $emit () are bubbled from the child scope to the parent scope, and all scopes above the scope of the event are notified of this event.

$broadcast (name, args)

With $emit parameters, name as the name of the event, args as the listener accepts parameters. The propagation direction of the event using this method is from top to bottom, that is, from the parent scope to the child scope.

Monitoring of events

Event is published, we are registering the service to monitor the event before responding to the event
Event Listener events can be registered through the $on () method.

$scope. $on (name, LISTENERFN)

The LISTENERFN event is executed after an event with name as the event name is sent.
$on () returns an anti-registration function that can be used to cancel the listener.

Event Object

All event listeners the first parameter represents the event object, which has the following properties:
Targetscope scope object, the scope of the Send event
CurrentScope: Scope of the current processing event
Name: The names of events for the current event
Stoppropagation: Canceling further propagation of events triggered by $emit
Preventdefaul: Set the defaultpreevented flag to true to tell the child scope that there is no need to handle the event.
Defaultpreevented: Boolean value
Angular: Built-in events
$includeContentLoaded ($emit event)
Nginclude content reload, trigger from nginclude instruction

$includeContentRequested ($emit event)

It is sent from the scope of the call to Nginclude, and the event is published every time the content of the nginclude is requested.

$viewContentLoaded ($emit event)

Published from the Ngview scope when the Ngview content is reloaded

$locationChangeStart ($broadcast event)

The $locationchangestart event is triggered when the address of the browser is updated via the $location service

$locationChangeSuccess ($broadcast event)

triggered when the address of the browser is successfully changed

$routeChangeStart ($broadcast event)

The event is released from $rootscope before the routing change occurs

The event of-angularjs-18-angularjs's life in Lei's dog

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.