I have a routeprovider that assigns a controller to a different route.
.when('/page/:id', {
templateUrl: '/page/overview.ejs',
title: __('pageTitle'),
controller: 'PageCtrl'
}
and in the overview.ejs
I have something like this:
<div>
<div ng-controller="SubPageCtrl">
....
</div>
</div>
The question is: how do I access the property of PageCtrl
in SubPageCtrl
?
I tried to do this, but it does not work:
function PageCtrl ($scope) {
$scope.test = "testing";
}
function SubPageCtrl($scope) {
console.log($scope.$parent.test);
console.log($scope.test)
}
Both of them print out undefined
. Does anybody know how I can make it work?
Edit:
It turned out I put the $scope.test = "testing"; in a callback of a asynchronous call, so the data is not ready when I call the console.log.
Other than that, it should be just what Vignesh's response below