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