Javascript 触发器调整大小事件导致错误$digest已在进行中angularjs

Javascript 触发器调整大小事件导致错误$digest已在进行中angularjs,javascript,angularjs,Javascript,Angularjs,我试图在angualr js指令上设置resize active,因为即使我设置了该值,我的动态图也总是以scope.option.eidth=0开头。。经过多次尝试,我发现: window.dispatchEvent(new Event('resize')); 在我的浏览器中,它可以工作!但是如果我把这个放在我的指令中,它会引起错误 angular.js:11655 Error: [$rootScope:inprog] $digest already in progress http://e

我试图在angualr js指令上设置resize active,因为即使我设置了该值,我的动态图也总是以scope.option.eidth=0开头。。经过多次尝试,我发现:

window.dispatchEvent(new Event('resize'));
在我的浏览器中,它可以工作!但是如果我把这个放在我的指令中,它会引起错误

angular.js:11655 Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.3.15/$rootScope/inprog?p0=%24digest
我知道这是由作用域状态在摘要中而不是应用中引起的。。有没有办法验证这一点

我的代码:

(function() {
    var app = angular.module('dashboard.view', []);

    app.directive('dygraph', function(){
        return {
            restrict: 'E',
            scope: {
                data    : '=',
                options : '=?'
            },
            template: '<div id="graphDiv" style="width: 100%"></div>',
            link: function (scope, elem, attrs) {
                var div = elem.children()[0];
                scope.options.width = elem.parent()[0];

                console.log("scope.$$phase ",scope.$$phase);
                var graph = new Dygraph(div, scope.data, scope.options);
                if(scope.options.title=="Scanning" || scope.options.title=="Bytes" || scope.options.title=="Pakets"){

                    graph.ready(function(){

                        if(scope.$$phase!='$diggest'){
                            window.dispatchEvent(new Event('resize'));
                        }
                    });

                    console.log("scope.options.width 2",scope.options.width);
                }

            }        
        };
    });

})();
(函数(){
var app=angular.module('dashboard.view',[]);
app.directive('dygraph',function(){
返回{
限制:'E',
范围:{
数据:'=',
选项:'=?'
},
模板:“”,
链接:功能(范围、要素、属性){
var div=elem.children()[0];
scope.options.width=elem.parent()[0];
log(“scope.$$phase”,scope.$$phase);
var图=新的动态图(div,scope.data,scope.options);
if(scope.options.title==“扫描”| | scope.options.title==“字节”| | scope.options.title==“Pakets”){
graph.ready(函数(){
如果(范围$$phase!='$diggest'){
dispatchEvent(新事件('resize'));
}
});
log(“scope.options.width 2”,scope.options.width);
}
}        
};
});
})();