Objective
Angularjs with instructions at present ng-include
,, ng-view
, ng-switch
ng-repeat
. The reason for this is that these directives, though Angularjs internally, are the same as the directive
methods of implementation, the way they are used internally scope:true
, the child scopes inherit the role of the parent, and a separate child scope is built, and all bidirectional bindings are not implemented, Only the properties that inherit the parent from the child scope can be implemented individually.
Angularjs's inheritance is implemented through JavaScript's prototype inheritance, which means that the parent scope is on the prototype chain of the child scope. Because the retrieval of the prototype chain will only be triggered when the attribute is retrieved, it will not be triggered when the property value is changed. So we need to convert the original type to an object and bind the value to the object's properties.
As you can see in the example, after the transformation, you can implement the child to modify the properties of the parent scope. The original type can only inherit the scope of the parent class.
The implementation method currently looks at three kinds, the following time to introduce
Convert the original type to an object by adding {} to the parent scope.
The code is as follows:
Using the Controller as syntax to implement
controller as
In fact controller
, the equivalent of the example object, the principle is to convert the original type to object type.
Use $parent.name to invoke an internal method to implement.
Prototype inheritance means that the parent scope is on the prototype chain of the child scope, which is a feature of JavaScript.
The scope of the ANGULARJS also has the following internally defined relationships:
Scope. $parent A parent scope that points to scope;
scope.$ $childHead Point to the first child scope of scope;
scope.$ $childTail point to the last child scope of scope;
scope.$ $nextSibling point to the next contiguous scope of scope;
scope.$ $prevSibling Point to the previous adjacent scope of scope;
scope.$parent.name
gets a two-way binding to the parent scope by using it in a child scope.
Examples are as follows:
Summarize
The above is the whole content of ANGULARJS child scope problem, hope to everybody study and work can help. If you have any questions, you are welcome to come forward.