角1.2不再允许同一元素在多个相互隔离的范围指令? [英] Angular 1.2 no longer allows multiple isolated scope directives on same element?

查看:122
本文介绍了角1.2不再允许同一元素在多个相互隔离的范围指令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在角度项目中的某些code使用具有隔离范围,两个独立的指令。它们并不需要共享范围,相同的元件上简单地存在。他们都改变DOM方式略有不同,更重要的结合作为参数传递的值。

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 alter the DOM in slightly different ways, and importantly bind to values passed as arguments.

这曾在1.0,但1.2角产生,现在试图做到这一点,当一个错误

This worked in 1.0, however Angular 1.2 now generates an error when attempting to do this

多重指令要求的新的/隔离的范围

Multiple directives asking for new/isolated scope

提交历史角度出现变化1.2的行为,以保持两个独立的指令单独在相同的元素。这是一件好事,而且在相同的元素把两个属性指令时,它工作正常。

Based on the projects git history appears Angular 1.2 changes behaviour to keep two isolated directives on the same element separate. This is a good thing, and it works correctly when putting two 'Attribute' directives on the same element.

<div my:directive="myDirectiveData" my:other-directive="myOtherDirectiveData" />

工作如你所愿。

然而

<my:directive my:directive-data="myDirectiveData" my:other-directive="myOtherDirectiveData" />

抛出上述错误。 (多指令要求的新的/隔离的范围内)

Throws the above error. (Multiple directives asking for new/isolated scope)

在这种情况下我本来期望每个指令,依然并存用自己的非共享隔离范围。

In this scenario I would have expected each directive to still exist in parallel with their own unshared isolated scope.

这是在角1.2还是有可能的?

Is this still possible in Angular 1.2?

推荐答案

当多个指令都在相同的元素定义会发生什么摘要:

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

这篇关于角1.2不再允许同一元素在多个相互隔离的范围指令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆