角:事件消化完成并查看更新的 [英] Angular: event for digest completed and view updated

查看:107
本文介绍了角:事件消化完成并查看更新的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在那里当视图更新监听的事件吗?这是否与消化完毕,我要听这个怎么样?
比如有在DIV itemDetail输出一个​​观点:

is there an event to listen when the view is updated? Is it related to digest completed, should I listen to this and how? For example there is a view that outputs in div itemDetail:

<div id="itemDetail">{{titleOriginal}}</div>

和相应的控制器:

.controller('ItemDetailController', function($scope) {
    $scope.titleOriginal = "...";
    alert(angular.element("#itemDetail").html());
})

现在该警报将抛出{{titleOriginal}},而不是评估值...。所以我想我应该先等待视图进行更新,然后警觉。怎么样?什么时候?请帮助。

Now this alert would throw {{titleOriginal}} instead of evaluated value "...". So I guess I should first wait for view to be updated and then alert. How? When? Please help.

推荐答案

您可以使用 $超时这不会运行,直到消化周期完成。

You could use $timeout which will not be run until digest cycle completes.

$timeout(function(){
   // should be updated when this code is executed
});

$超时是一个角度对 window.setTimeoutset 包装。超时删除从执行队列中的功能和JavaScript已经与当前执行队列完成后它只会被调用。这样的方式您的模型将被执行之前更新。

$timeout is an Angular's wrapper for window.setTimeoutset. Timeout removes the function from the execution queue and it will only be invoked after JavaScript has finished with the current execution queue. So that is way your model will be updated before the execution.

这篇关于角:事件消化完成并查看更新的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆