Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Naming Angular directives (ng- vs data-ng-)

What is the recommended practice for labelling Angular directives?

Other than html validation, are there any other benefits to prefixing both the in-built and my own custom directives with "data-"?

Or is it unnecessary clutter?

like image 969
Brett Postin Avatar asked Apr 18 '13 07:04

Brett Postin


People also ask

What is the difference between data Ng and Ng?

The difference is simple - there is absolutely no difference between the two except that certain HTML5 validators will throw an error on a property like ng-app , but they don't throw an error for anything prefixed with data- , like data-ng-app .

What is the difference between ng model and data NG model?

For AngularJS there is no difference between ng-app and data-ng-app or ng-controller and data-ng-controller or ng-model and data-ng-model because while compiling HTML page, AngularJS strips data- or x- prefix.

Can we use data Ng instead of Ng?

You can use data-ng-, instead of ng-, if you want to make your page HTML valid.

Which type of directives starts with * ng?

AngularJS directives are extended HTML attributes with the prefix ng- . The ng-app directive initializes an AngularJS application.


1 Answers

I would say data- would be best practice. Since this will allow the html to validate, it should be a standard practice for developers. It may cause a bit of clutter, but overall I think it helps maintain the intergrity of the app and of the developer. And seeing as it doesn't matter to angular that I can tell thus far, then there really is no reason not to use data-.

like image 196
selanac82 Avatar answered Oct 23 '22 09:10

selanac82