AngularJS - is it possible to underline the name of a directive?


I have a problem with the angular link naming directive and the angular way to normalize the names of my directives.
To follow some naming conventions in an existing project, to which I want to add angular, I need to specify my custom directive with "_" like this:

app.directive("directive_name", function(...) {...});

It is sad that this contradicts the angular way of normalizing the directive name, and as a result, such directives are ignored, not compiled, and therefore not displayed on the screen.

[Question]
Is it possible to name the directive in such a way that later we can use it in HTML as follows:

<body>
    ...
    <my_directive></my_directive>
</body>

Thanks for your time and help!

+4
2

, , :

app.directive("yourDirectiveName", function(...) {...});

:

<your_directive_name></your_directive_name>

, angularjs, , html jqLite camelCase

https://github.com/angular/angular.js/blob/v1.0.x/src/jqLite.js#L106

, - :

SPECIAL_CHARS_REGEXP = /([\:\-\_]+(.))/g;
+5

, , camelCase:

app.directive("directiveName", function(...) {...});

HTML

<my_directive></my_directive>

imho - ,

<my-directive></my-directive>

angular html :

  • Strip x- data- /.
  • :, - _ -delimited name camelCase.
+9

Source: https://habr.com/ru/post/1545341/


All Articles