[英]How to access scope in a function inside link function in angularjs directive?
This might not be an angularJS problem but I am at my wit's end here. 这可能不是angularJS的问题,但我的观点到此为止。 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
How do I access the scope inside the callback function of 'preload', where it says scope is not accessible here ? 如何在“预载”的回调函数中访问作用域,该作用域表示此处无法访问作用域?
If you need the DOM to be ready you can do this inside the link function (the scope will be accessible): 如果您需要准备好DOM,则可以在链接函数中执行此操作(可以访问范围):
$timeout(function(){
alert('DOM ready');
//** scope accessible here **
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.