O'Reilly logo

AngularJS Directives by Alex Vanston

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Naming

Naming of directives within Angular is pretty flexible, with a few conventions implemented to ensure consistency. All directives are named using camelCase in JavaScript, and snake case within your HTML. Snake case, here, means all lower case, using either :, -, or _ to separate the words. Thus, for us, the JavaScript name myAwesomeDirective becomes my-awesome-directive, my:awesome:directive, or my_awesome_directive in the HTML, all of which will properly bind the directive to the DOM node. And finally, if you're running your HTML through a validator and don't like seeing warnings about each of your custom directives, you can even prepend x- or data- to the directive name and Angular will still detect it.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required