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

查看:168
本文介绍了为什么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规范允许您使用未知标记(< tab> 面板> ),而没有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天全站免登陆