- For native types on $scope, such as $scope.name= "";
- When you get a variable from a scope, you look for the scope itself, and you find the parent scope
- When modified, if the scope does not exist, a variable is created in this scope, and the variables of the parent scope are not looked up and modified
- For objects on $scope, such as $scope.name={};
- When you get a variable from a scope, you look for the scope itself, and you find the parent scope
- When modified, if the scope does not exist, the variables of the parent scope are looked up and modified
1 <!DOCTYPE HTML>2 <HTML>3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Title</title>6 </Head>7 <Body>8 <DivNg-app= "MYAPP">9 <DivNg-controller= "Parentcontroller">Ten {{name}} One <BR/> A {{Name1.value}} - <DivNg-controller= "Childcontroller"> - {{name}} the <BR/> - {{Name1.value}} - </Div> - </Div> + </Div> - <Scriptsrc=".. /angular-1.5.8/angular.js "></Script> + <Script> A varapp=Angular.module ('myApp',[]); at App.controller ('Parentcontroller',function($scope) { - $scope. Name= "1"; - $scope. name1={}; - $scope. Name1.value="2"; - }); - App.controller ('Childcontroller',function($scope) { in //$scope. Name= "3"; - //$scope. Name1.value="4"; to }); + - </Script> the </Body> * </HTML>
Parent scope and self-scope in Angularjs