Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name conventions in angualrjs directives

Tags:

angularjs

This works for me (server-side validation example):

AngularJS: integrating with server-side validation

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/>

But when creating the directive, we use 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?

I just wonder because when I used <input ... required uniqueEmail it does not work. Until I typed "unique-email"

Same if I type:

app.directive('unique-email', function($http) {

It will not work until I type uniqueEmail

So there is no chance to use one style name when use directive and when define it.

like image 894
ses Avatar asked Oct 21 '13 19:10

ses


1 Answers

From 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.

So, yes it is an angular convention.

like image 88
Davin Tryon Avatar answered Nov 25 '22 00:11

Davin Tryon