Angularjs - 元素多重指令与一个孤立的存在范围 [英] Angularjs - Multiple directives on element with one being isolate scope

查看:167
本文介绍了Angularjs - 元素多重指令与一个孤立的存在范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想,如果有人可以解释当前的行为。

Wondering if someone can explain the current behavior.

我有一个指令与分离范围,称之为DIRA。后来我把另外一个指令就可以了,DIRB。期待第二个指令来获得每个范围的分离指令造成的。

I have one directive with isolate scope, call it dirA. I then put another directive on it, dirB. Expecting the second directive to get each scope that the isolate directive creates.

DIRB得到控制范围。它为什么不得到DIRA是创建该元素的分离相同的范围?

dirB gets the controller scope. Why would it not get the same isolate scope that dirA is creating for that element?

感谢您的帮助。我真的没有任何code这一点,只是好奇。如果有人需要两个小指令和一些HTML帮助形象化我当然会。谢谢你。

Thanks for any help. I don't really have any code for this, just curious. If anyone needs two little directives and some html to help visualize i will of course. thank you.

推荐答案

在观察什么是正确的,这种行为是设计使然。

What you observe is correct and this behavior is by design.

当一个指令要求的隔离范围,AngularJS会为伪指令,其中指令宣布对元素的范围,具体地说,不可以。换句话说,隔离是每个指令,而不是每个元件。这使得编码可重复使用的和独立的指令比如​​果一个人有防范来自其他指令隔离范围的使用不当容易多了。

When a directive requests an isolated scope, AngularJS creates a scope for that directive specifically, not for the element where the directive is declared on. In other words, the isolation is per-directive, not per-element. This makes coding reusable and standalone directives much easier than if one has to guard against improper usage of the isolated scope from other directives.

在相同的元件共享外部声明的所有其他指令。 (另外值得一提的是,这些指令不能甚至要求自己的范围,孤立的或没有。虽然这种行为是不是之前的1.3保证,由于一个bug,它已经是<一个href=\"https://github.com/angular/angular.js/commit/2cde927e58c8d1588569d94a797e43cdfbcedaf9\">fixed 1.3。)

All other directives declared on the same element share the outer scope. (It's also worth noting that these directives can't even request their own scope, isolated or not. While this behavior is not guaranteed prior to 1.3 due to a bug, it is already fixed in 1.3.)

这篇关于Angularjs - 元素多重指令与一个孤立的存在范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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