Directive with root element with ngRepeat and replace: true

后端 未结 1 2003
执笔经年
执笔经年 2021-01-24 12:27

Can someone explain the root cause behind the following behavior?

If a directive with isolate scope scope: {} has a root element with ng-repeat

相关标签:
1条回答
  • 2021-01-24 13:20

    It does not just happen for ng-repeat, this seems to happen for any other directives that creates a scope like ng-if as well. And it seems like, this is because the directive's isolated scope gets overwritten by the ng-repeat's child scope. And because of replace:true option ng-repeat becomes a part of the directive source element i.e <foo></foo> and the child scope of ng-repeat is calculated from the ultimate parent scope MainCtrl (Which appears to be wrong) and this causes the entire directive template to be bound to the child scope of controller and any interpolations are evaluated against that scope. Hence you see main controller's scope being expanded in the directive. This seems like a bug.

    0 讨论(0)
提交回复
热议问题