I have an Angular template in the DOM.
(我在DOM中有一个Angular模板。)
When my controller gets new data from a service, it updates the model in the $scope, and re-renders the template.(当我的控制器从服务获取新数据时,它会更新$ scope中的模型,然后重新呈现模板。)
All good so far.(到目前为止都很好。)
The issue is that I need to also do some extra work after the template has been re-rendered and is in the DOM (in this case a jQuery plugin).
(问题是我需要在模板重新渲染之后做一些额外的工作并且在DOM中(在这种情况下是一个jQuery插件)。)
It seems like there should be an event to listen to, such as AfterRender, but I can't find any such thing.
(似乎应该有一个事件要听,比如AfterRender,但我找不到任何这样的事情。)
Maybe a directive would be a way to go, but it seemed to fire too early as well.(也许一个指令是一种可行的方式,但它似乎也太早了。)
Here is a jsFiddle outlining my problem: Fiddle-AngularIssue
(这是一个概述我的问题的jsFiddle : Fiddle-AngularIssue)
== UPDATE ==
(==更新==)
Based on helpful comments, I've accordingly switched to a directive to handle DOM manipulation, and implemented a model $watch inside the directive.
(根据有用的评论,我相应地切换到一个指令来处理DOM操作,并在指令中实现了一个模型$ watch。)
However, I still am having the same base issue;(但是,我仍然有同样的基础问题;)
the code inside of the $watch event fires before the template has been compiled and inserted into the DOM, therefore, the jquery plugin is always evaluating an empty table.($ watch事件内部的代码在模板编译并插入DOM之前触发,因此,jquery插件总是在评估一个空表。)
Interestingly, if I remove the async call the whole thing works fine, so that's a step in the right direction.
(有趣的是,如果我删除异步调用,整个过程就可以了,所以这是朝着正确方向迈出的一步。)
Here is my updated Fiddle to reflect these changes: http://jsfiddle.net/uNREn/12/
(这是我更新的小提琴反映这些变化: http : //jsfiddle.net/uNREn/12/)
ask by gorebash translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…