我的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文档中找到和source code 。
This is all called attribute normalisation (US: attribute normalization) and can be found in the AngularJS documentation and source code.
更多推荐
角指令名:只允许小写字母?
发布评论