为什么AngularJS建议不要使用XML命名空间? [英] Why does AngularJS not recommend using XML namespaces?

查看:88
本文介绍了为什么AngularJS建议不要使用XML命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AngularJS指令具有纳克 - prefixed给他们。它为什么坚持让使用preFIX的,而不是使用一个实际的XML命名空间?

AngularJS directives have ng- prefixed to them. Why does it insist on making use of a prefix instead of using an actual xml namespace?

的文档:

如果您选择使用老式的指令语法NG:然后包括HTML,使IE快乐XML的命名空间。 (这是这里由于历史原因,我们不再建议使用纳克。)

使用这样的事情似乎工作:

Using something like this does seem to work:

<html xmlns:ng="http://angularjs.org" ng:app="my-app">

此的jsfiddle 。

但不建议使用它,支持它的只是由于历史的原因的。有人能指出我什么这些原因可能是什么?从Flex背景的,我认为XML命名空间是巨大的,我很愿意使用它们,但也许有充分理由的角度去与preFIX的方法呢?

But it does not recommend using it and supports it just for historical reasons. Can someone point me to what those reasons might be? Coming from a Flex background, I think XML namespaces are great and I would love to make use of them, but perhaps there is are strong reasons for Angular to go with the prefix approach?

推荐答案

我想知道这个自己。考虑两个独立项目,小工具厂和袋熊框架,每发展指令 X 。这是 preferred实践以preFIX指令名,以避免名字空间的冲突,但在这种情况下,每个可能仍然最终限定 WF-X

I've wondered about this myself. Consider two independent projects, "Widget Factory" and "Wombat Framework" that each develop directive x. It's preferred practice to prefix directive names to avoid namespace conflicts, but in this case, each might still end up defining a wf-x.

如果我使用,会发生什么&LT; D​​IV WF-X =东西&GT;&LT; / DIV&GT; 包含两个模块的应用程序?有趣的是,角将连接两者的优先级依次连接每个。但是,这产生正确的结果的可能性是很低的。角如果两个指令尝试添加一个控制器,两个指令的语义和他们期望的元素的属性和结构的价值很容易互相冲突将引发一个错误。

What happens if I use <div wf-x="something"></div> in an application containing both modules? Interestingly, angular will attach both, linking each in descending priority order. But the odds of this producing a correct result are low. Angular will raise an error if both directives try to add a controller, and the semantics of the two directives and what they expect for the value of the attribute and structure of the element could easily conflict with one another.

在XML中,这个问题解决了命名空间。 &LT; D​​IV的xmlns:WF1 =...WF1:X =东西&GT;&LT; / DIV&GT; &LT; WF1:点¯x的xmlns:WF1 =...&GT;&LT; / WF1点:x&GT; 不是pretty,但他们清楚地描述了指令,我们打算用

In XML, this problem is solved with namespaces. <div xmlns:wf1="..." wf1:x="something"></div> or <wf1:x xmlns:wf1="..."></wf1:x> aren't pretty, but they clearly describe which directive we intend to use.

为什么没有棱角的支持呢? XML命名空间是罕见的,可能不是一般的HTML很好的支持,并有可能与解析技术挑战。指令中的意见和CSS类以及元素和属性的支持,而将不得不在类名莫名其妙错位。最简单的答案,虽然可能是因为它不是一个常见的​​问题,不够还需要什么超过prefixes我们今天所使用的先进的看到。应当指出的是角的当前方法是通过 Web组件的建议之一。作为该标准的发展,我希望的角度对其进行跟踪。有一些讨论对聚合物组以及这个话题

Why doesn't angular support this? XML namespaces are uncommon and may not be well-supported in general HTML, and there may be technical challenges with parsing. Directives are supported in comments and CSS classes as well as elements and attributes, and : would have to be mangled somehow in a class name. The simplest answer though may be that it's not a common enough problem yet to require anything more advanced than the prefixes we see in use today. It should be noted that angular's current approach is the one recommended by Web Components. As that standard evolves, I would expect angular to track it. There's some discussion on this topic in the Polymer group as well.

这篇关于为什么AngularJS建议不要使用XML命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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