我正在尝试使用指令显示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.
}
};
}]);
答案 0 :(得分: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.
});
}
};
}]);