Name conventions in angualrjs directives

前端 未结 2 1018
误落风尘
误落风尘 2020-12-09 18:58

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

AngularJS: integrating with server-side validation

But, I decided to ask additional question.

In

相关标签:
2条回答
  • 2020-12-09 19:45

    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.

    0 讨论(0)
  • 2020-12-09 19:50

    It is html convention to use only lower case for tags and attributes (partly because HTML5 is not case sensitive. class="" is the same as ClaSS=""). Angular didn't want to constrain your directive names to lower case. So it allows the use of upper case within Angular and then handles turning those names into the html standard snake case for you.

    So you get naming flexibility, and improved readability, in Angular while staying compliant with html naming standards.

    Note, that if you only use lower case names you won't have to worry about the name conversion. Of course, that'll likely come at the expense of readability of your Angular code.

    0 讨论(0)
提交回复
热议问题