Ng-App Vs. Data-Ng-App, What Is the Difference

ng-app vs. data-ng-app, what is the difference?

Good question. 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.

So to answer your question, use data-ng-app if you would like validating your HTML to be a bit easier.

Fun fact: You can also use x-ng-app to the same effect.

ng-app V/S data-ng-app in AngularJS

Both and are the same except for the fact that if you want your template/code to be according to be HTML compliant and follow the best practices. Use data-ng-app.

This is what the official documentation quotes:

"Best Practice: Prefer using the dash-delimited format (e.g. ng-bind for ngBind). If you want to use an HTML validating tool, you can instead use the data-prefixed version (e.g. data-ng-bind for ngBind). The other forms shown above are accepted for legacy reasons but we advise you to avoid them."

Hope that answers your question.

Cheers!

What is the difference between data-ng and ng?

It's just for validation of your HTML. No other purpose.

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

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-.

Angularjs, using data-ng-controller and ng-controller

Angularjs uses a normalization process for directive name / attributes matching.

From the angularjs docu at http://docs.angularjs.org/guide/directive.

Section Matching Directives:

The normalization process is as follows:

Strip x- and data- from the front of the element/attributes.
Convert the :, -, or _-delimited name to camelCase.



Related Topics



Leave a reply



Submit