我用以下命令调用指令:
<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
如何在范围内访问此对象?
调查是否异步加载到控制器中latestSurvey
?其中一个原因scope.survey
是undefined
可能是因为请求没有完成,该项目是空的。
我建议您尝试设置$scope.latestSurvey
一些虚拟数据,看看问题是否仍然存在。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句