2015-10-12 17 views
1

我试图显示一个使用指令的UI网格页脚的外部作用域。外部范围在表格中正确显示,但当我尝试在链接功能中访问它时,该变量未定义。想法?未定义的外部示波器用户界面

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

回答

0

我认为问题是,你尝试获得财产之前的任何值由其父指令分配。尝试将您的指令更改为:

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.   
      }); 
     } 
    }; 
}]);