在angualrjs指令名称约定 [英] Name conventions in angualrjs directives
问题描述
这对我的作品(服务器端验证为例):
This works for me (server-side validation example):
<一个href=\"http://stackoverflow.com/questions/12864887/angularjs-integrating-with-server-side-validation\">AngularJS:与服务器端验证整合
不过,我决定问另一个问题。
But, I decided to ask additional question.
在我们使用的例子唯一的电子邮件指令:
In that example we use unique-email directive:
<input type="email" ng-model="userEmail" name="userEmail" required unique-email/>
但是,创造指令时,我们使用 uniqueEmail
app.directive('uniqueEmail', function($http) { ..
为什么呢?难道是主题相关的命名惯例/规则的名称?如何角知道去哪里找,以及如何连接一个到另一个?
Why? Is it related somehow to name conventions / rules in names? How does angular know where to look and how to connect one to another?
我只是奇怪,因为当我使用&LT;输入...需要uniqueEmail
这是行不通的。直到我输入的是独特的电子邮件
I just wonder because when I used <input ... required uniqueEmail
it does not work. Until I typed "unique-email"
相同的,如果我输入:
app.directive('unique-email', function($http) {
它不会工作,直到我键入 uniqueEmail
因此,有没有机会使用一种风格名字的时候使用的指令,当定义它。
So there is no chance to use one style name when use directive and when define it.
推荐答案
指令有骆驼套管的名称,如ngBind。该指令可以
通过翻译驼峰名字进入蛇的情况下使用这些调用
特殊字符:, - 或_。可选的指令可以
prefixed以x-或DATA-使它HTML验证标准。
Directives have camel cased names such as ngBind. The directive can be invoked by translating the camel case name into snake case with these special characters :, -, or _. Optionally the directive can be prefixed with x-, or data- to make it HTML validator compliant.
所以,是的,它是一个棱角分明的约定。
So, yes it is an angular convention.
这篇关于在angualrjs指令名称约定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!