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

非 Y 不嫁゛ 提交于 2019-12-04 14:34:04

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!

Tom Willson

See the answer:

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

Only diffrence regarding html5 validation

Yoeri

ng-app isn't strictly valid html. Custom attributes should be prefixed with data- to be valid.

So angular added this syntax so users could still have valid html. (Knockout also uses data- attributes.) There is absolutely no difference in functionality.

Source: w3.org - custom data attributes

ng-app and data-ng-app both are similar to each other, the only difference between them is sometimes HTML validators will show an error while using ng-app. so that time you can use data-ng-app.

note: x-ng-app also have the same property. You can use x-ng-app too instead of using data-ng-app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!