angular中扩展集成ngModel.$render不起作用的问题解决
程序员文章站
2022-04-17 20:53:00
...
遇到这种情况,可能是因为还有其他的指令在同时覆盖$render,导致自己写的集成扩展又一次被覆盖掉了
比较常见的就是,在Input中,写了一个directive,而这里面自己要覆盖ngModel.$render
我遇到的情况就是input的监听ngModel把我的给覆盖掉了,导致我写的内容无法执行
解决办法就是在指令里面添加priority属性
这个属性是用来排序的
也就是在同一个标签内,使用了多个指令,会有先后的compile和link的顺序,这个属性就是用来排序的,默认为0
官方文档内容如下
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.
比较常见的就是,在Input中,写了一个directive,而这里面自己要覆盖ngModel.$render
我遇到的情况就是input的监听ngModel把我的给覆盖掉了,导致我写的内容无法执行
解决办法就是在指令里面添加priority属性
这个属性是用来排序的
也就是在同一个标签内,使用了多个指令,会有先后的compile和link的顺序,这个属性就是用来排序的,默认为0
官方文档内容如下
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.
上一篇: PHP垃圾回收机制的理解