angularjs - angularjs 指令中的命名约定

标签 angularjs

这对我有用(服务器端验证示例):

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/

相关文章:

javascript - Keycloak 未知提供程序错误

angularjs - 为什么 ace 编辑器加载所有文本突出显示以及如何删除它?

javascript - Angular - 使用 ng-click 后 Controller 刷新

javascript - 如何使用 javascript 填写 ng-model 查询以过滤数据?

angularjs - 将新数据添加到滚动上的预输入结果中

jquery - Angular 将页面转换为可下载或通过电子邮件发送的 html

javascript - 通过 Nodejs 将原始 HTML 发送到电子邮件 hoganjs 模板,从而在电子邮件客户端上提供原始 HTML 输出

javascript - angularjs过滤器notarray不是数组

javascript - 使用多个选择选项的搜索功能 - angularjs

javascript - 使用 javascript chrome 扩展触发 AngularJS 表单验证