这对我有用(服务器端验证示例):
AngularJS: integrating with server-side validation
但是,我决定再问一个问题。
在那个例子中,我们使用 唯一邮箱 指令:
<input type="email" ng-model="userEmail" name="userEmail" required unique-email/>
但是在创建指令时,我们使用 uniqueEmail :
app.directive('uniqueEmail', function($http) { ..
为什么?它是否与名称中的命名约定/规则有关? angular 如何知道看哪里以及如何将一个连接到另一个?
我只是想知道因为当我使用
<input ... required uniqueEmail
时它不起作用。直到我输入“唯一邮箱”如果我输入也一样:
app.directive('unique-email', function($http) {
在我输入
uniqueEmail
之前它不会工作所以在使用指令和定义它时没有机会使用一个样式名称。
最佳答案
来自 here :
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.
所以,是的,这是一个 Angular 约定。
关于angularjs - angularjs 指令中的命名约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19503121/