未定义的外部范围 ui-grid

Undefined external Scope ui-grid

我正在尝试使用指令显示 ui- 网格页脚的外部范围。外部作用域在 table 上正确显示,但当我尝试在 link 函数中访问它时变量未定义。想法?

app.directive('testDir',[function(){
    return {
        restrict: 'E',
        replace: true,    
        transclude: true,
        template: '<div>{{t1.val}}</div>',
        scope: {
          t1: '='
        },link: function(scope){
          console.log(scope); //=====>t1 is there in the console.
          console.log(scope.t1); //=====>t1 is undefined in console.          
        }
    };  
}]);

http://plnkr.co/edit/qas0f23oE6RJOuYzrcOm?p=preview

我认为问题在于您试图在其父指令分配任何值之前获取 属性。尝试将您的指令更改为:

app.directive('testDir',['$timeout', function($timeout){
  return {
        restrict: 'E',
        replace: true,    
        transclude: true,
        template: '<div>{{t1.val}}</div>',
        scope: {
          t1: '='
        },link: function(scope){
          $timeout(function() {
              console.log(scope); //=====>t1 is there in the console.
              console.log(scope.t1); //=====>t1 is undefined in console.          
          });
        }
  };  
}]);