angualrjs 指令中的命名约定 [英] Name conventions in angualrjs directives
问题描述
这对我有用(服务器端验证示例):
This works for me (server-side validation example):
但是,我决定再问一个问题.
But, I decided to ask additional question.
在那个例子中,我们使用 unique-email 指令:
In that example we use unique-email directive:
<input type="email" ng-model="userEmail" name="userEmail" required unique-email/>
但是在创建指令时,我们使用uniqueEmail:
But when creating the directive, we use uniqueEmail:
app.directive('uniqueEmail', function($http) { ..
为什么?它是否与名称中的命名约定/规则有关?angular 如何知道往哪里看以及如何将一个连接到另一个?
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?
我只是想知道,因为当我使用 <input ... required 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.该指令可以是通过将骆驼案例名称翻译成蛇案例来调用这些特殊字符 :、- 或 _.可选的指令可以是以 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屋!