Scope Nesting of ANGULARJS training

Source: Internet
Author: User

Each part of the ANGULARJS application has a parent scope (but Ng-app corresponds to the $rootscope, this scope is the ultimate scope), except for the isolate scope, all scopes are created through prototype inheritance, This means that you can access the scope of its parent. If you're familiar with OOP, you'll be familiar with this behavior.

Every time the HTML rendering properties and methods are searched from the current scope, if not found, they are searched from his parent scope until the $rootscope is retrieved and an error is made if they are not found.


Let's look at an example:

<div ng-controller= "Parentcontroller" >

Parent:{{parent}} <br>

Parent-to-child: {{child}}

<div ng-controller= "Childcontroller" >

Child: {{child}} <br>

Child-to-parent: {{parent}}

</div>

</DIV>


The controller is defined as follows:

var app = Angular.module (' demo ', []);

App.controller (' Parentcontroller ', function ($scope) {

$scope. Parent = ' parentstring '

});

App.controller (' Childcontroller ', function ($scope) {

$scope. Child = ' childstring '

});


Run your own code ah, do not lazy ah!

From the running results, the methods in the parent scope can be accessed directly in child scope. If you have a public property in your scenario, you can define it in the parent scope.

Okay, bye, see you next time!

This article is from the "Eason's HCC" blog, so be sure to keep this source http://hcc0926.blog.51cto.com/172833/1559742

Scope Nesting of ANGULARJS training

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.