在AngularJS指令定义HTML标签的后果 [英] Consequences of Custom HTML Tags in AngularJS Directives

查看:130
本文介绍了在AngularJS指令定义HTML标签的后果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我写了一个自定义的的gravatar 指令在AngularJS绑定到一个电子邮件的范围属性。该指令将取代这个HTML ...

Say I wrote a custom gravatar directive in AngularJS that is bound to an email property on the scope. The directive would replace this HTML …

<gravatar email="user.email" />

,由该的src 属性设置为正确的Gravatar URL共同 IMG 标签:

by a common img tag whose src attribute is set to the correct Gravatar url:

<img src="http://gravatar.com/avatar/..." />

我的问题可能有点宽泛,甚至幼稚,但怎么坏是它最初有&LT;的gravatar /&gt;在我的网页的HTML 标记?是否有任何真实世界的后果,除了没有通过W3C验证?

My question might be a little broad or even naïve, but "how bad" is it to initially have the <gravatar /> tag in my page's HTML? Are there any "real-world" consequences besides not passing W3C validation?

推荐答案

W3C的说

创作者不应该使用元素,属性或属性值比其相应的预期语义其他用途,从正确处理页面这样做prevents软件。

Authors must not use elements, attributes, or attribute values for purposes other than their appropriate intended semantic purpose, as doing so prevents software from correctly processing the page.

创作者不应该使用的元素,属性或属性不受此规范或<允许的价值href=\"http://www.w3.org/html/wg/drafts/html/master/infrastructure.html#other-applicable-specifications\">other适用的规范的,因为这样做使得显著更难的语言在将来进行扩展。

Authors must not use elements, attributes, or attribute values that are not permitted by this specification or other applicable specifications, as doing so makes it significantly harder for the language to be extended in the future.

<一个href=\"http://www.w3.org/html/wg/drafts/html/master/dom.html#elements\">http://www.w3.org/html/wg/drafts/html/master/dom.html#elements

自定义元素/属性没有语义价值,应当避免这些原因。

Custom elements/attributes have no semantic value and should be avoided for these reasons.

有可能不会有任何的直接的后果,你甚至会发现。毕竟,角本身使用非确认纳克属性(虽然他们做的数据支持 - preFIX以及)。

There probably won't be any direct consequences that you will even notice. After all, Angular itself uses the non-confirming ng attributes (although they do support with the data- prefix as well).

您可能面临的唯一可能的问题是,如果你介绍该元素是目前的自定义元素成为规范的一部分,并且具有比之前所希望的不同的行为,但我认为这是极不可能的。即便如此,我想如果我能避免使用任何自定义的。

The only possible problem you may face is if the element you introduce that is currently a custom element becomes part of the spec and has different behavior than what you were expecting before, but I think that is highly unlikely. Even so, I would avoid using anything custom if I could.

最终你将可以注册自己的自定义元素,但我可以告诉没有浏览器支持该规范还没有。

Eventually you will be able to register your own custom elements, but from what I can tell no browser supports this spec yet.

这篇关于在AngularJS指令定义HTML标签的后果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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