can we access to one controller’s $scope from another controller? I need to get the entire data in parent,child and grandchild controller is it possible
Here is my script
var app = angular.module('myApp', []);
app.controller('ParentController',ParentController);
function ParentController($scope)
{
$scope.parentName="Parent"
}
app.controller('ChildController1',ChildController1);
function ChildController1($scope)
{
$scope.childName1="Child1"
}
app.controller('ChildController2',ChildController2)
function ChildController2($scope)
{
$scope.childName2="Child2"
}
app.controller('GrandChildController1',GrandChildController1);
function GrandChildController1($scope)
{
$scope.grandChildName1="GrandChild1"
}
Here is my view code
<div> ng-app="myApp">
<div ng-controller="ParentController">
Parent:{{parentName}}
Child1:{{childName1}}
Child2:{{childName2}}
GrandChild1:{{grandChildName1}}
<div ng-controller="ChildController1">
Parent:{{parentName}}
Child1:{{childName1}}
Child2:{{childName2}}
GrandChild1:{{grandChildName1}}
<div ng-controller="GrandChildController1">
Parent:{{parentName}}
Child1:{{childName1}}
Child2:{{childName2}}
GrandChild1:{{grandChildName1}}
</div>
</div>
<div ng-controller="ChildController2">
Parent:{{parentName}}
Child1:{{childName1}}
Child2:{{childName2}}
GrandChild1:{{grandChildName1}}
</div>
</div>
</div>
I didn't get the child scope in parent controller.Wht will i do.Write any service or something.Thank you