角指令名:只允许小写字母? [英] Angular directive name: only lower case letters allowed?

查看:104
本文介绍了角指令名:只允许小写字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的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屋!

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