title: AngularJS How to access Controller scope from Directive
body: <p>I am trying to access parent controller scope from a directive function. When I try to get the value of <code>$scope.$parent</code> it returns me the object. But when I try to access any variable from that object it returns <strong><em>Undefined</em></strong>.</p>
  
  <pre><code>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'
      };
  }]);
  </code></pre>
  
  <p>First <code>console.log($scope.$parent)</code> return the following output: 
  <a href="https://i.stack.imgur.com/q1Oki.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/q1Oki.png" alt="enter image description here"></a></p>
  
  <p>But <code>$scope.$parent.assignmentInfo</code> return <code>underfined</code></p>
  
  <p>How do I access the <code>assignmentInfo</code>?</p>