【发布时间】:2015-01-11 23:33:07
【问题描述】:
我正在调用指令:
<latest-survey survey="latestSurvey"></latest-survey>
我的指令的代码是:
function latestSurvey(){
return {
restrict: 'E',
templateUrl: 'js/modules/survey/latest.html',
scope: {
survey: '=survey'
},
link: function(scope, element, attrs){
console.log(scope);
console.log(scope.survey);
}
}
}
console.log(scope) 行输出范围:
Scope {$id: "007", $$childTail: null, $$childHead: null, $$prevSibling: null, $$nextSibling: null…}
$$asyncQueue: Array[0]
$$childHead: null
$$childTail: null
$$destroyed: false
$$isolateBindings: Object
$$listenerCount: Object
$$listeners: Object
$$nextSibling:
$$childScopeClass
$$phase: null
$$postDigestQueue: Array[0]
$$prevSibling: null
$$watchers: Array[3]
$id: "007"
$parent:
$$childScopeClass
$root: Scope
survey: Object
this: Scope
__proto__: Scope
如您所见,survey 列在那里,我可以在控制台中浏览它以查看其属性。但是,下一行console.log(scope.survey) 输出:
undefined
如何在作用域内访问这个对象?
【问题讨论】:
-
如果在指令模板中使用
{{survey}}会发生什么? -
列出调查对象。我可以在模板中访问它,但由于某种原因不能在链接功能中访问。
-
看起来非常好。尝试发布 sn-p 或小提琴?
-
尝试将您的控制台日志 od scope.survey 包装到
$timeout中,并在超时 0 和 100 中显示您所拥有的内容。
标签: angularjs angularjs-directive angularjs-scope