AngularJS指令为"自定义" HTML标签。这不是危险的,可能会与未来的HTML版本冲突? [英] AngularJS directives as "custom" HTML tags: isn't this dangerous and may conflict with future HTML versions?

查看:180
本文介绍了AngularJS指令为"自定义" HTML标签。这不是危险的,可能会与未来的HTML版本冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在读了很多关于不同的JS框架(EmberJS,AngularJS,等等)。

I'm currently reading a lot about different JS frameworks (EmberJS, AngularJS, etc.).

在第一眼,我喜欢使用这样的自定义HTML标签指令AngularJS'的想法:

On first sight, I loved AngularJS' idea of using directives like custom HTML tags:

<mytag>...</mytag>

但不是这种危险?如果我定义了很多这样的标签,然后有一个高的可能性,未来的HTML规范也可以定义我的自定义标签之一,但完全是另外一个意思!

But isn't this dangerous? If I define a lot of such tags, then there's a high likelihood that a future HTML spec may also define one of my custom tags, but with a whole other meaning!

我知道,自定义标签可以通过HTML规范本身被允许:

I know that custom tags may be allowed by the HTML spec itself:

http://w3c.github.io/webcomponents/spec/custom/

但此刻,事实并非如此。因此,它是使用自定义的标签,指示好的做法呢?或者我应该更好地依靠 NG-XXX 属性?

But at the moment, it isn't. So is it good practice to use custom tags as directives? Or should I better rely on ng-xxx attributes?

推荐答案

我觉得你很安全创建自己的元素指令。一个未来的HTML标记出来具有相同名称的风险相当低。

I think you're quite safe creating your own element directives. The risk of a future HTML tag coming out with the same name is quite low.

您也可以命名空间的指令,这将降低显著未来命名冲突的风险。

You can also namespace your directives, and this will significantly reduce the risk of any future naming conflicts.

假设你的应用程序名称为MyApp的,你可以有这样的事情:

Let's say that your app name is "MyApp", you could have something like this:

<ma-custom-tag></ma-custom-tag>

这也协助避免可能添加到您的项目中的任何角度模块冲突。被释放的大多数角图书馆应该有一定的命名空间。

This also assists with avoiding conflicts in any angular modules you may add to your project. Most angular libraries that are released should have some namespacing.

该角项目有这个概念倒是一个最佳实践的Wiki:的https: //github.com/angular/angular.js/wiki/Best-Practices

The Angular project has a best practices Wiki that touches on this concept: https://github.com/angular/angular.js/wiki/Best-Practices

这篇关于AngularJS指令为&QUOT;自定义&QUOT; HTML标签。这不是危险的,可能会与未来的HTML版本冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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