错误:使用警报时,$消化已经在angularjs进展警报、进展、错误、angularjs

由网友(╰ 一抹淡淡的抹茶)分享简介:我刚刚从控制器服务JSON数据。 和我使用一个回调函数,当它得到加载到打印成功消息。它工作正常,但它也扔,我在问题中提到的错误 // JSON文件{PC:名}//角服务VAR的服务= angular.module('服务',['ngResource'])。工厂('小工具',函数($资源){    返回$资源('/ J...

我刚刚从控制器服务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)。在此期间,你的警觉导致该问题。

重庆疾控 2月5日以来 广州 南宁来渝返渝人员请报备

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.

阅读全文

相关推荐

最新文章