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?
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 .
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.
You can use data-ng-, instead of ng-, if you want to make your page HTML valid.
AngularJS directives are extended HTML attributes with the prefix ng- . The ng-app directive initializes an AngularJS application.
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-.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With