Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
818 views
in Technique[技术] by (71.8m points)

angularjs - Name conventions in angualrjs directives

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...