I am trying to access parent controller scope from a directive function. When I try to get the value of $scope.$parent it returns me the object. But when I try to access any variable from that object it returns Undefined.
app.controller('myCtrl', function ($scope, $http, $timeout) {
$scope.init = function(){
$http.get('url.php').success(function(data){
$scope.assignmentInfo = data.record;
});
};
});
app.directive('getInfo', [function(){
return {
restrict: 'A',
scope:{
data:'=',
title: '='
},
link:function(scope, elem, attrs){
scope.$watch('data.visible', function(val){
// do something
});
},
controller: function($scope) {
console.log($scope.$parent); // return an object
console.log($scope.$parent.assignmentInfo); // return undefined
},
templateUrl: 'template.html'
};
}]);
First console.log($scope.$parent) return the following output:

But $scope.$parent.assignmentInfo return underfined
How do I access the assignmentInfo?