Prefer having a prefix for all directive namesJS-0536
It is recommended to have a consistent naming for the directive. It is easy to mash all the directives in one file, but it is difficult to break those out, so some are shared across apps, some across modules, some just for one module.
We recommend having one directive per file. One directive per file is easy to maintain. Provide a short, unique and descriptive directive prefix such as acmeSalesCustomerInfo
which would be declared in HTML as acme-sales-customer-info
. The unique short prefix identifies the directive's context and origin.
Naming Angular Directives
A prefix of cc-
may indicate that the directive is part of a CodeCamper app, while acme-
may indicate a directive for the Acme company.
We recommend not to use ng-
as a prefix because it is a reserved keyword for Angular directives.
For directive component names, use consistent names for all directives using camelCase. Use a short prefix to describe the directives' belong (some examples are company prefix or project prefix). Provides a consistent way to identify and reference components quickly.
Note: This issue is raised only when the project has an existing ESLint configuration file.
Bad Practice
// error: The navigation directive should follow this pattern: /^ui/
angular
.module('myModule')
.directive('navigation', function () {
// ...
});
Recommended
angular
.module('myModule')
.directive('prefixTabs', function () {
// ...
});