为什么 Angular 不需要组件名称中的破折号 [英] Why does Angular not need a dash in component name

查看:30
本文介绍了为什么 Angular 不需要组件名称中的破折号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么 Polymer 元素需要在像 <my-component> 这样的自定义元素名称中使用破折号,而这对于 Angular 组件来说不是必需的,尤其是因为 Angular 组件也使用 ShadowDOM.

I wondered why Polymer elements need a dash in custom elements name like <my-component> while this is not necessary for Angular components especially as Angular components also use ShadowDOM.

** 编辑**在 Angular 中,它甚至似乎都不是建议的好习惯.

** Edit** It doesn't even seem to be suggested good practice in Angular.

推荐答案

HTML 规范允许您使用未知标签(, ) 没有 HTML 解析器抛出一个合适的.为了他们的利益,Angular 在他们的指令中使用这种行为来使组件像原生一样.

The HTML spec allows you to use unknown tags (<tab>, <panel>) without the HTML parser throwing a fit. To their benefit, Angular uses this behavior for their directives to make the components like native.

没有 - 的标签继承自 HTMLUnknownElement.这里对升级过程有很好的解释:HTML5Rocks - 自定义元素 - 元素如何升级了

Tags that don't have a - inherit from HTMLUnknownElement. There's a good explanation of the upgrade process here: HTML5Rocks - Custom Elements - How elements are upgraded

由于 Angular 指令是在自定义元素规范存在之前设计的,因此它们不使用 -.这是要求元素名称包含 - 的标准.

Since Angular directives were designed in a time before the Custom Elements spec existed, they don't use a -. It's the standard that requires element names contain a -.

这篇关于为什么 Angular 不需要组件名称中的破折号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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