问题描述
限时送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:关键词]
发布评论