0 votes
in Angular by
What Kind of Naming Conventions Is Used for Custom Directives?

1 Answer

0 votes
by

For angular custom directive, the best practice is to follow camel casing and that also with at least two letters. In camel case naming convention, we start with a small letter, followed by a capital letter for every word.

Some example of camel cases are loopCounterisValid and so on.

So when you register a custom directive, it should be with camel case format as shown in the below code companyCopyRight.

HTML
app.directive('companyCopyRight', function ()
{
return
{
        template: '@CopyRight questpond.com '
 };
});

Later when this directive is consumed inside HTML before each capital letter of camel case, we need to insert a - as specified in the below code.

HTML
<div company-copy-right></div>

Image 27

If you are making a one letter prefix like copyright, it’s very much possible that tomorrow if HTML team creates a tag with the same name, it will clash with your custom directive. That’s why Angular team recommends camel case which inserts a - in between to avoid further collision with future HTML tags.

Related questions

0 votes
asked Dec 29, 2023 in Angular by DavidAnderson
0 votes
asked Dec 31, 2023 in Angular by DavidAnderson
...