2

I have the following 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>

The issue that I am having is that the tabs directive is running before the the ng-repeat directive.

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)?

4

2 回答 2

4

一个指令可以在三个不同的时间“运行”,因为一个指令可以具有编译、预链接和后链接方法。 这个 plunker包含两个示例 HTML 结构——一个使用 ng-repeat,一个不使用——它会在 3 个指令函数中的每一个运行时打印出来。

对于 ng-repeat 示例,我们看到 ng-repeat 链接前和链接后功能在 nag-tabs 链接后运行。因此,如果您想让 tabs 指令在 ng-repeat 后链接函数运行后执行某些操作,则必须使用 $timeout(如建议的 @charlietfl)或 $watch 或事件来执行代码之后。

您可以尝试向checklastng-repeat 元素添加一个指令,该指令可以在 is 时向您的 tabs 指令发出$last信号true。信号可以通过一个事件来完成,或者 checklast 指令可以是require您的 tabs 指令,然后 checklast 指令可以调用您的 tabs 指令控制器上的方法。另请参阅https://stackoverflow.com/a/13906907/215945

请注意,漂亮的 plunker 来自Peter

于 2013-03-02T21:27:34.657 回答
0

你控制 tab 指令吗?如果是这样,则修改其编译阶段以将 ng-repeat 添加到其子元素。

于 2013-03-05T01:02:01.573 回答