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