问题描述
在我的AngularJS应用程序,有一个在我想等待一个$范围被加工成DOM,然后在其上运行一些code,就像一个jQuery淡入,例如几个百分点。
In my AngularJS app, there's several points at which I want to wait for a $scope to be processed into the DOM, and then run some code on it, like a jquery fadeIn, for example.
有没有听某种形式的digestComplete消息的方式吗?
Is there a way to listen for a digestComplete message of some sort?
我目前的方法是,设定什么$范围变量我想渲染后,立即使用的setTimeout 0毫秒的延迟,因此,它可以让范围内完成消化,然后运行code,它完美的作品。唯一的问题是,我很偶然看到的setTimeout返回之前的DOM渲染。我想这是保证摘要火后,并呈现前一种方法。任何想法?
My current method is, immediately after setting whatever $scope variables I want rendered, use setTimeout with a delay of 0 ms, so that it will let the scope finish digesting, and then run the code, which works perfectly. Only problem is, I very occasionally see the DOM render before that setTimeout returns. I'd like a method that is guaranteed to fire after digest, and before render. Any ideas?
推荐答案
在此(我发现它 wiki页面的:看的通过MISKO,他在其中指出:
Another possible solution is to use $evalAsync: see this comment by Miško, in which he states:
该asyncEval是DOM施工后,但在浏览器呈现前。
我相信这是你要附加的jQuery插件的时间。除此以外
你会有闪烁。如果你真的想要做的浏览器渲染后
你可以做$延迟(FN,0);
($延迟更名为$超时)。
($defer was renamed $timeout).
不过,我觉得用指令(因为你操纵DOM)是更好的方法。
However, I think using a directive (since you are manipulating the DOM) is the better approach.
下面是一个SO张贴其中OP尝试监听上的范围$ viewContentLoaded事件(这是又一替代),以适用于一些jQuery函数。建议/答案是再次使用指令。
Here's a SO post where the OP tried listening for $viewContentLoaded events on the scope (which is yet another alternative), in order to apply some jQuery functions. The suggestion/answer was again to use a directive.
这篇关于AngularJS:火灾后$范围立即事件$消化。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!