Angular 指令名称:只允许小写字母?

编程入门 行业动态 更新时间:2024-10-28 16:19:16
本文介绍了Angular 指令名称:只允许小写字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我的代码:

app.directive('abcabc', function (){ alert('directive');}); // working

但是

app.directive('abcAbc', function (){ alert('directive');}); // not working !
app.directive('abc-abc', function (){ alert('directive');}); // not working !

我做错了吗?还是 Angular 指令有特殊的命名规则?

Am I doing wrong? Or there are special naming rules for Angular directive?

推荐答案

AngularJS 试图让每个人都开心!

AngularJS attempts to make everyone happy!

有些人更喜欢使用数据属性,比如 data-abc-abc,我想是为了让验证者开心.其他人更喜欢使用像 abc:abc 这样的命名空间,而其他人更喜欢使用实际的指令名称 abcAbc.甚至全部大写ABC_ABC.或者像 x-abc-abc 这样的扩展属性.

Some people prefer to use data attributes, like data-abc-abc, I assume to keep validators happy. Other people prefer to use namespaces like abc:abc, and others prefer to use the actual directive name abcAbc. Or even all caps ABC_ABC. Or extension attributes like x-abc-abc.

AngularJS 将 HTML 中使用的名称标准化以试图涵盖所有这些情况.data-x- 被剥离,剩余部分用 :-_ 作为单词边界.这使得 abcAbc 从上面提到的案例中得到,用于查找 JavaScript 中声明的指令.

AngularJS normalises the name used in HTML to attempt to cover all of these cases. data- and x- are stripped, the remainder camelcased with :, - and _ as word boundaries. This makes abcAbc from the cases mentioned above, which is used to look up the directive declared in JavaScript.

这都称为属性规范化(美国:属性规范化),可以在 AngularJS 文档中找到

This is all called attribute normalisation (US: attribute normalization) and can be found in the AngularJS documentation and source code.

这篇关于Angular 指令名称:只允许小写字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-21 23:30:54,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指令   只允许   字母   名称   Angular

发布评论

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

>www.elefans.com

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