2015-10-12 2 views
1

Я пытаюсь отобразить внешнюю область для нижнего колонтитула ui-grid с помощью директивы. Внешняя область отображается правильно в таблице, но переменная не определена, когда я пытался получить к ней доступ в функции ссылок. мысли?Undefined external Scope ui-grid

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.   
      }); 
     } 
    }; 
}]); 
Смежные вопросы