让内部指令之前外指令angularjs运行 [英] Let inner directives run before outer directives angularjs
问题描述
我有以下的html:
<div nag-tabs="tabsOptions">
<ul class="tabs">
<li ng-repeat="tab in tabs">{{ tab }}</li>
</ul>
<div class="tab_content">
<div ng-repeat="tabContent in tabsContent">{{ tabContent }}</div>
</div>
</div>
这是我遇到的问题是,标签指令在该NG重复指令之前运行。
The issue that I am having is that the tabs directive is running before the the ng-repeat directive.
有没有什么办法让标签指令所有的指令后,运行,涵盖了老马标签指令运行的内容(NG-重复或任何其他可能被摆在那里)?
Is there any way to get the tabs directive to run after all the directives that encompasses the content of the nag-tab directive run (ng-repeat or whatever else might be put in there)?
推荐答案
一个指令可以在运行在三个不同的时间,因为一个指令可以编译,pre-链接,链接后的方法。 这plunker 包含两个示例HTML结构&ndash的;人使用NG重复,一个不&ndash的;它打印出每时的3指令功能的运行。
A directive can "run" at three different times, because a directive can have compile, pre-link, and post-link methods. This plunker contains two sample HTML structures – one uses ng-repeat, one doesn't – and it prints out when each of the 3 directive functions runs.
对于NG重复的例子中,我们看到了NG-重复pre型和后链接功能老马的选项卡后连杆后运行。所以,如果你想拥有的标签指令做运行NG重复链接后功能后的东西,你将不得不使用一个$超时(如@charlietfl建议)或$手表,或者一个事件,执行$ C $ç更高版本。
For the ng-repeat example, we see that the ng-repeat pre- and post- link functions run after the nag-tabs post-link. So if you want to have the tabs directive do something after the ng-repeat post-link functions run, you'll have to use a $timeout (like @charlietfl suggested) or a $watch, or an event, to execute the code later.
您可以尝试添加 checklast
指令这可能意味着你的标签指令时, $最后
是真正
。信号可以通过事件来完成,或者checklast指令可要求
您的标签指令,然后checklast指令可以调用一个方法,你的标签指令的控制器。
参见<一个href=\"http://stackoverflow.com/a/13906907/215945\">http://stackoverflow.com/a/13906907/215945.
You could try adding a checklast
directive to the ng-repeat element which could signal your tabs directive when $last
is true
. Signalling could be done via an event, or the checklast directive could require
your tabs directive and then the checklast directive could call a method on your tabs directive's controller.
See also http://stackoverflow.com/a/13906907/215945.
请注意,在漂亮的plunker来自彼得。
Note, the nifty plunker came from Peter.
这篇关于让内部指令之前外指令angularjs运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!