A detailed discussion on the angularjs of the _angularjs of the child scope

Source: Internet
Author: User
Tags inheritance

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:

<! DOCTYPE html>  

Using the Controller as syntax to implement

controller asIn fact controller , the equivalent of the example object, the principle is to convert the original type to object type.

<! DOCTYPE html>  

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.namegets a two-way binding to the parent scope by using it in a child scope.

Examples are as follows:

<! DOCTYPE html>  

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.

Related Article

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.