本文介绍了如何访问angularjs指令中链接函数内函数的作用域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这可能不是 angularJS 的问题,但我的机智到此为止.代码如下所示:
This might not be an angularJS problem but I am at my wit's end here. The code is shown below:
prep.directive('resultgraph', function () {
return {
restrict: 'A',
link: function (scope, element, attrs) {
//** scope accessible here **
DomReady.ready(function () {
ThreeBox.preload([
'/scripts/lib/snippets.glsl.html',
], function () {
//....scope not accessible here
如何访问 'preload' 回调函数中的作用域,它说此处无法访问作用域?
How do I access the scope inside the callback function of 'preload', where it says scope is not accessible here ?
推荐答案
如果您需要准备好 DOM,您可以在链接函数中执行此操作(范围将是可访问的):
If you need the DOM to be ready you can do this inside the link function (the scope will be accessible):
$timeout(function(){
alert('DOM ready');
//** scope accessible here **
});
这篇关于如何访问angularjs指令中链接函数内函数的作用域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!