Scope of ANGULAJS

Source: Internet
Author: User

Scope ($scope)

is essentially a function of the object, the role: to store the data model, provide the context for the expression, listen to the expression changes and propagate events, is an important bridge between view and controller.

1. Features

A $watch method is provided to monitor the change of the data model, and the bidirectional data binding implemented by Ng-model is to monitor the data model by invoking the method.

The $watch method monitors the variation of the model data, mainly because within Angula, when modifications are made to the properties specified by the binding Ng-model, the internal $digest method is automatically executed once, detecting the value of the property bound by Ng-mode with the last $ The digest method executes when the content obtained is consistent, and if not, executes the handler for the $watch method binding.

Provides another $apply method that provides support for various types of data model changes, such as executing the code in the controller through the Ng-click designation in view;

Provides an environment for an expression to execute, scoped by providing a $scope object so that all expressions have a corresponding execution environment, that is, the context object that executes.

2. Scope of the action data model

The scope is not only the controller and view bridge, but also the view and the specified bridge, because in the custom instruction, will call the $watch method to listen to the changes of the individual expressions, once the scope of the expression has changed, $wathc method will notify the command, The instruction will re-render the DOM page based on this change, i.e. update the property value contents in the scope.

Both specified and controller, they can be bound to the DOM in the view by scope. Thus, the birth of 2 data relationship links, one is: Specify the scope->view, the other is:controller-> $scope->view, the 2 relationship between the chain is independent of each other.

3. Hierarchy and events of the scope

When the scope is bound to a page element, it forms its own hierarchical relationship based on the hierarchical relationship of the elements, in which they can communicate data through the propagation of events, except that the application scenario of this event-based data communication is limited and limited to the scope between the parent and the child.

Scope of ANGULAJS

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.