角指令名:只允许小写字母? [英] Angular directive name: only lower case letters allowed?
问题描述
我的code:
app.directive('abcabc', function (){ alert('directive');}); // working
但
app.directive('abcAbc', function (){ alert('directive');}); // not working !
app.directive('abc-abc', function (){ alert('directive');}); // not working !
难道我做错了吗?
或者有折角指令特殊的命名规则?
Am I doing wrong? Or there are special naming rules for Angular directive?
推荐答案
AngularJS试图让所有人都满意!
AngularJS attempts to make everyone happy!
有人preFER使用数据的属性,如数据-ABC-ABC
,我想保持验证高兴。其他人preFER使用的命名空间,比如 ABC:ABC
,和其他preFER使用实际的指令名 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中用于试图覆盖所有这些情况的名称。 数据 -
和 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文档中找到和<一个href=\"https://github.com/angular/angular.js/blob/dafb8a3cd12e7c3247838f536c25eb796331658d/src/ng/compile.js#L2029\">source code 。
This is all called attribute normalisation (US: attribute normalization) and can be found in the AngularJS documentation and source code.
这篇关于角指令名:只允许小写字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!