gpt4 book ai didi

javascript - Angular 中的指令优先级不起作用

转载 作者:搜寻专家 更新时间:2023-11-01 04:52:01 24 4
gpt4 key购买 nike

我有这个元素:

<div ace-editor dl-editor></div>

还有这些指令:

angular.module('DLApp')


.directive 'aceEditor', () ->
restrict: 'A'
priority: 10
scope: false
link: linkFunc1

.directive 'dlEditor', (Graph) ->
restrict: 'A'
priority: 0
scope: false
link: linkFunc2

(我知道 0 是默认值)

dlEditor总是先执行,然后 aceEditor .我做错了什么?

最佳答案

根据 the docs :
强调我的

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.

因此,具有更高优先级 ( aceEditor ) 的指令首先被编译,但它的后链接功能(这似乎是您感兴趣的功能)最后运行。

您应该移动预链接功能中的逻辑(如果适用于您的情况)或反转优先级。

关于javascript - Angular 中的指令优先级不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22389094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com