Javascript AngularJS链接函数的顺序不正确
如果我在另一个指令的模板中包含一个指令,并且Javascript AngularJS链接函数的顺序不正确,javascript,html,angularjs,angularjs-directive,Javascript,Html,Angularjs,Angularjs Directive,如果我在另一个指令的模板中包含一个指令,并且transclude将内容放入其中,那么它的link函数将在任何被转移的指令之前被调用 例如(另请参阅): 我有以下由指令和模板组成的HTML <body ng-app="showcase"> <reel> <asset></asset> </reel> <script type="text/ng-template" id="reel.html"
transclude
将内容放入其中,那么它的link函数将在任何被转移的指令之前被调用
例如(另请参阅):
我有以下由指令和模板组成的HTML
<body ng-app="showcase">
<reel>
<asset></asset>
</reel>
<script type="text/ng-template" id="reel.html">
<div class="reel">
<div class="inner" scrollable ng-transclude></div>
</div>
</script>
<script type="text/ng-template" id="asset.html">
<div class="asset" ng-transclude></div>
</script>
</body>
控制台的预期输出为:
asset
scrollable
reel
因为资产
是可滚动
的子项,但是我得到:
scrollable
asset
reel
是否有人知道我如何取回订单,但仍然在
卷轴
模板中定义附加指令?如果在同一元素上使用指令,则需要设置优先级。默认情况下,用户定义的指令的优先级为0。尝试将资产设置为优先级:10
如果在同一元素上使用指令,则需要设置优先级。默认情况下,用户定义的指令的优先级为0。尝试将资产设置为优先级:10。@CorySilva我使用
终端属性声明其优先级始终为最后一个ngTransclude
的优先级显然为0。@CorySilva实际上有效。。。但奇怪的是,航站楼没有。你想回答我,我会接受吗?@CorySilva抱歉的评论。。。我误解了终端的属性。。。这意味着以后的任何优先事项都不会运行。我认为这意味着无论发生什么事情,都要把它作为最新的优先事项。哎呀,我甚至没有注意到你有终端的财产;我对那处房产也有同样的第一印象。很高兴你成功了!
scrollable
asset
reel
/** ### Directive Definition Object
*
* The directive definition object provides instructions to the {@link ng.$compile
* compiler}. The attributes are:
*
* #### `priority`
* When there are multiple directives defined on a single DOM element, sometimes it
* is necessary to specify the order in which the directives are applied. The `priority` is used
* to sort the directives before their `compile` functions get called. Priority is defined as a
* number. Directives with greater numerical `priority` are compiled first. Pre-link functions
* are also run in priority order, but post-link functions are run in reverse order. The order
* of directives with the same priority is undefined. The default priority is `0`.
*
* #### `terminal`
* If set to true then the current `priority` will be the last set of directives
* which will execute (any directives at the current priority will still execute
* as the order of execution on same `priority` is undefined).
*/