How to access scope in a function inside link function in angularjs directive?

邮差的信 提交于 2019-12-12 03:17:02

问题


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

How do I access the scope inside the callback function of 'preload', where it says scope is not accessible here ?


回答1:


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 **
});


来源:https://stackoverflow.com/questions/27920293/how-to-access-scope-in-a-function-inside-link-function-in-angularjs-directive

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!