为什么不能多指令要求在相同的元素一个孤立的范围是什么? [英] Why can't multiple directives ask for an isolated scope on the same element?

查看:128
本文介绍了为什么不能多指令要求在相同的元素一个孤立的范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果<一个href=\"http://stackoverflow.com/questions/26692263/angularjs-multiple-directives-on-element-with-one-being-isolate-scope\">Angularjs - 元素多重指令其中一人为隔离范围是正确的,孤立的范围势必指令,那么,为什么会有任何冲突?此错误的文档指出处理它们会导致冲突或不支持的配置。我不买这个。多重指令已经共享元素的范围,这是肯定的地方冲突/不支持的配置会进来。我试图寻找为什么这个,而是纷纷拿出空手而归。

If Angularjs - Multiple directives on element with one being isolate scope is right, the isolated scope is bound to the directive, so why would there be any clashes? The documentation for this error states that processing them would result in a collision or an unsupported configuration. I don't buy this. Multiple directives already share the element's scope, which is surely where clashes/unsupported configurations would come in. I've tried looking for the "why" on this, but have come up empty handed.

有人能解释/举一个例子,这将确实产生碰撞或不支持的配置?

Can someone explain / give an example where this would indeed create a collision or an unsupported configuration?

推荐答案

答案很简单 - 需要有只有一个范围的子元素绑定到(的看源),因为分配到后代元素进行作用域属性需要有一个清晰的目标。剩下的就是措辞的问题。

Why can't multiple directives on the same element get separate isolated scopes

The answer is simple - there needs to be only one scope to bind the child elements to (see source), because assignments to scope properties done in descendant elements need to have a clear target. The rest is a question of wording.

虽然这是合适的,在某种程度上,是指被创建该特定指令的范围分离(如链接的回答一样),它仅在这个意义上,所要求的隔离的指令是指示该元素上的唯一的 的能够获得的分离的范围。因此,将创建的范围的指令的并从该DOM的级别的其余子元素的隔离

While it is appropriate, in a way, to refer to the isolate scope being created "for that particular directive" (as the linked answer does), it is only in the sense that the directive that requested the isolation is the only one of the directives on that element to have access to the isolated scope. So, the scope is created to isolate the directive and the child elements from the rest of that "level" of DOM.

允许多个用户指令相同的隔离范围将风险范围绑定配置的冲突(多指令,可以尝试绑定到同一属性上孤立的范围内)。

Giving multiple directives the same isolated scope would risk a clash of scope binding configurations (multiple directives could try to bind to the same property on the isolated scope).

一个简单的和令人信服的说法是, {{interpolated.ex pressions}} 元素上需要对同一范围被评价为纯EX pressions (提供给支持他们的指令),否则整个事情将是一团糟。 (例如,作为内插 {{EX pressions}} 单独完成的,指令接受纯EX pression 中的一个属性和字符串在另一个可与针对不同的范围进行评估前pressions进行配置。)

A simple and compelling argument is that the {{interpolated.expressions}} on an element need to be evaluated against the same scope as plain expressions (supplied to directives that support them), otherwise the whole thing would be a total mess. (E.g., as the interpolation of {{expressions}} is done separately, a directive accepting a plain expression in one attribute and String in another, could be configured with expressions evaluated against different scopes.)

如果他们真的需要,他们可以访问的隔离范围(但这需要的调试数据启用)。如果他们有优先级低于该指令创建隔离范围,他们可以只使用 element.isolateScope()在他们的连接功能(的看演示)。

If they really need to, they can access the isolated scope (but this needs Debug Data to be enabled). If they have lower priority than the directive creating the isolate scope, they can just use element.isolateScope() in their linking function (see demo).

这篇关于为什么不能多指令要求在相同的元素一个孤立的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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