Watch of Angularjs

Source: Internet
Author: User

Brief introduction

First, the Apply method will trigger the Evel method, and when the Evel method resolves successfully, it will trigger the digest method, and the digest method will trigger the watch method.

When Digest executes, it is triggered if watch observes that the value is not the same as the last execution.

Angularjs's internal watch realizes the timely updating of the page with the model.

$watch method is used primarily to manually listen for an object, but an event is triggered when the object changes. 】

Grammar

$watch (Watchfn,watchaction,deepwatch)

WATCHFN: This parameter is a string with an angular expression or function that returns the current value of the data model being monitored. This expression will be executed many times, so make sure it doesn't produce any other side effects. In other words, make sure it can be called many times without changing the state. For the same reason, the monitoring expression should be easily computed. If you use a string to pass a angular expression, it will be executed against the object in the scope that called it.

watchaction (newvalue,oldvalue,scope): This is a function or expression that will be called when the WATCHFN is changed. If it is in the form of a function, it will receive the new and old two values of WATCHFN, as well as a reference to the scope object. Its function signature is functions (NewValue, OldValue, scope).

Deepwatch: If set to True, this optional boolean parameter will command angular to check whether each property of the monitored object has changed. You can use this parameter if you want to monitor an element in an array, or all of the properties on an object, rather than just monitoring a simple value. Because angular need to traverse arrays or objects, if the collection is larger, the computational burden will be heavier.

$watch will return a function that you want to unregister this watch with.
var dereg = $scope. $watch (' Somemodel.someproperty ', Callbackonchange ()); Dereg ();

Usage

 
    

Effect: Http://runjs.cn/detail/vnlh0eny


Angularjs Watch

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.