The difference between angular's $watch and $digest and $apply and $observe

Source: Internet
Author: User

$watch represents the listener of the data source, and when the data source changes, the second parameter's callback function is triggered
$digest represents an event that triggers a change in the data source
$apply represents a package for $digest, he has one more parameter.

$watch  

$digest

is used to trigger a listener event manually, usually without the need for manual triggering, but by $apply to invoke

$apply

Just put $digest in a package, to provide manual triggering, then why need to manually trigger it, under normal circumstances, in angular, modify the data source will automatically trigger, but if not in the context of angular, such as browser DOM events, settimeout execution, In this case, angular cannot get to the event, so, by using apply to manually trigger, in the parameters of apply to modify the data source

$observe


attr, which is actually the attribute parameter on the defined element, can get the parameter   in the DOM by attr;
through $observe to listen, when the value of the parameter changes, it will trigger a callback function, The difference between him and watch is that the listener's host object is different


The difference between angular's $watch and $digest and $apply and $observe

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.