为什么Angular不需要在组件名称中使用破折号

编程入门 行业动态 更新时间:2024-10-19 17:38:59
本文介绍了为什么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不需要在组件名称中使用破折号

本文发布于:2023-08-02 11:34:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1277472.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:破折号   要在   不需   组件   名称

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!