[英]Async ran during digest phase
I'm running this code in an Angular service, immediately upon loading the page. 加载页面后,我正在Angular服务中运行此代码。 The controller $scope is passed as an argument to the function this extract belong to.
控制器$ scope作为该摘录所属函数的参数传递。 The function is a $q promise.
该函数是$ q的承诺。
I am not able to figure out how can I let the controller know that scope.req.rows
has been updated. 我无法弄清楚如何让控制器知道
scope.req.rows
已更新。 If I add scope.$apply()
right after it, I run into a running digest phase. 如果我在它之后添加
scope.$apply()
,我将进入运行摘要阶段。 If I use the $q resolve
function, it returns and no more loop results are returned. 如果使用$ q
resolve
函数,它将返回并且不再返回任何循环结果。 scope.$evalAsync()
and $timeout
seem to have no effect (at least without setting a timeout > 0). scope.$evalAsync()
和$timeout
似乎没有效果(至少没有将timeout设置为> 0)。 Same goes for scope.$watch
. scope.$watch
。
How can I let the controller know that values were updated? 如何让控制器知道值已更新?
for (var page = 0; page < nbPages; page++) {
(function (pageNum) {
that.get(url,
where,
res.pageSize * page,
res.pageSize)
.then(function Success(data) {
$log.info('Result of page ' + pageNum + ' received');
for (row in data) {
scope.req.rows++;
}
}).catch(function chunkFail(err) {
reject(err);
});
})(page);
I build simple demo and it`s works. 我构建了简单的演示,并且可以正常工作。 Correct me if i wrong.
纠正我,如果我错了。
Updated : i mocking http request and delay it form 1000ms to 30000ms. 更新 :我嘲笑http请求并将其从1000ms延迟到30000ms。 and i steel have't any scope problems.
我钢铁没有任何示波器问题。 http://jsbin.com/wasoxe/4/edit?js,output
http://jsbin.com/wasoxe/4/edit?js,output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.