<div ng-controller= "Oparentcontroller as Pctrl" >
<p> direct access to the value of the parent controller:{{user}}</p>
<div ng-controller= "Ochildcontroller as Cctrl" >
<p> How to access the nested: Parent controller value: failed: <input ng-model= "Puser"/> Success: <input ng-model= "Obj2.puser"/></p>
<p> Sub-controller value:{{user}}</p>
<button ng-click= "Modiv ()" >CLK: Modify the values within the parent controller (scope) within the child controller </div>
</div>
</div>
<script>
var a10086=angular.module (' a10086 ', []);
A10086.controller (' Oparentcontroller ', function ($scope) {
$scope. user= ' parent_ John Doe ';
$scope. Msg={a: ' Parent_ John Doe ', b:4,c:[1,34]};
}). controller (' Ochildcontroller ', function ($scope) {
$scope. user= ' child_ Zhang San ';
$scope. puser= $scope. msg.a;
$scope. obj2={
Puser: $scope. msg.a
};
$scope. Modiv=function () {
$scope. msg.a= "Parent_ John Doe is modify";
$scope. obj2.puser= "Parent_ John Doe is modify---obj";
Console.log (' sub-control does not have MSG, but modified along the prototype chain: ', $scope. MSG, $scope. Puser);
}
});
</script>
How to access variables in a parent controller within a child controller