错误:使用警报时,$消化已经在angularjs进展 [英] Error: $digest already in progress in angularjs when using alert
问题描述
我刚刚从控制器服务JSON数据。
和我使用一个回调函数,当它得到加载到打印成功消息。它工作正常,但它也扔,我在问题中提到的错误
// JSON文件
{
PC:名
}//角服务
VAR的服务= angular.module('服务',['ngResource'])。
工厂('小工具',函数($资源){
返回$资源('/ JSON / home.json',{},{
查询:{方法:GET,则params:{},IsArray的:假}
});
});//控制器
功能editWidget($范围,窗口小部件){
$ scope.data = Widgets.query(功能(数据){
警报(成功加载数据--->中+ JSON.stringify(data.pc));
});
}
警报
,以及确认
和提示
将暂停code(块的线程)的执行,在此期间,超时和时间间隔全力以赴失控,如果他们应该已经在暂停期间触发。在 $消化
循环是由两个小圈,哪个过程 $ evalAsync
队列和 $手表
列表。在 $ evalAsync
队列用于调度这就需要当前栈帧以外发生的工作,但浏览器的看法之前渲染。这通常是做的setTimeout(0)
。在此期间,你的警觉导致该问题。
I am just getting the json data from the services in the controller.
And I am using a callback function to print the success message when it got loaded. It is working fine but it is also throwing an error which I mentioned in the question
//JSON file
{
"pc":"name"
}
// angular services
var service = angular.module('Services', ['ngResource']).
factory('Widgets', function($resource){
return $resource('/json/home.json', {}, {
query: {method:'GET', params:{}, isArray:false}
});
});
//controller
function editWidget($scope, Widgets) {
$scope.data = Widgets.query(function(data) {
alert("Success Data Loaded ---> " + JSON.stringify(data.pc));
});
}
alert
, as well as confirm
and prompt
will pause the execution of code (blocks the thread), during which timeouts and intervals go all haywire if they should have been triggered during the pause. The $digest
loop is made up of two smaller loops, which process $evalAsync
queue and the $watch
list. The $evalAsync
queue is used to schedule work which needs to occur outside of current stack frame, but before the browser's view render. This is usually done with setTimeout(0)
. Your alert during this time causes the problem.
这篇关于错误:使用警报时,$消化已经在angularjs进展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!