Angular 1.2 no longer allows multiple isolated scope directives on same element?

后端 未结 2 1004
我寻月下人不归
我寻月下人不归 2020-12-30 15:14

I have some code in an Angular project that use two separate directives with isolated scope. They do not need to share scope, simply exist on the same element. They both alt

相关标签:
2条回答
  • 2020-12-30 16:11

    You can't have multiple directives asking for isolate scope on the same element. I think your problem may be caused by this unresolved issue in angularjs.

    0 讨论(0)
  • 2020-12-30 16:16

    Summary of what happens when multiple directives are defined on the same element:

      Scenario  directive #1   directive #2   Result
         1      no new scope   no new scope   Both directives use the controller's scope.
                                              (This should be obvious.)
         2      new scope      new scope      Both directives share one new child scope.
         3      new scope      no new scope   Both directives share one new child scope.
                                              Why does dir #2 use the child scope?
                                              This seems odd to me.
         4      isolate scope  no new scope   Angular v1.0: both directives share the
                                              isolate scope.
                                              Angular v1.2+: dir #1 uses the isolate scope,
                                              dir #2 uses the controller's scope.
    

    Note that the following scenarios are not allowed (Angular throws an error):

      Scenario  directive #1   directive #2
         5      isolate scope  new scope
         6      isolate scope  isolate scope
    
    0 讨论(0)
提交回复
热议问题