Angularjs 如果我把我的自定义指令放在ng If中,它的链接函数永远不会被调用

Angularjs 如果我把我的自定义指令放在ng If中,它的链接函数永远不会被调用,angularjs,angularjs-directive,angular-directive,angular-ng-if,Angularjs,Angularjs Directive,Angular Directive,Angular Ng If,即使最终显示了元素 如果我把它放在ngshow中而不是ngif,它会工作,但它也需要在ngif中工作 ng if和ng show都伴有ng斗篷 自定义指令: var customDirective = [function() { return { restrict: 'A', require: '?^^customSuperAttribute', link: function(scope, element, attrs, ctrl) { console.l

即使最终显示了元素

如果我把它放在
ngshow
中而不是
ngif
,它会工作,但它也需要在
ngif
中工作

ng if
ng show
都伴有
ng斗篷

自定义指令:

var customDirective = [function() {
  return {
    restrict: 'A',
    require: '?^^customSuperAttribute',
    link: function(scope, element, attrs, ctrl) {
      console.log('link called')
      //...
    }
  }
]
angular.module(module.exports).directive('customAttribute', customDirective)
<span ng-cloak ng-if="variable" custom-attribute>abc</span>
指令的使用:

var customDirective = [function() {
  return {
    restrict: 'A',
    require: '?^^customSuperAttribute',
    link: function(scope, element, attrs, ctrl) {
      console.log('link called')
      //...
    }
  }
]
angular.module(module.exports).directive('customAttribute', customDirective)
<span ng-cloak ng-if="variable" custom-attribute>abc</span>
abc

链接
函数的任务是替换
span
的文本。

不清楚您的代码与问题描述之间的关系。我添加了示例HTML。一切正常,指令被调用并执行它应该执行的操作,除非与
ng if
一起使用。对我来说正常。如果你能提供一个演示,它会有所帮助。在创建了小提琴之后,我认为你是对的: