Ng-app vs data-ng-app in Angular.js
We know the purpose of ng-app. Ng-app directive tells Angular.js that this is the root element of the application. All Angular.js apps must have a root element. You should only have one ng-app directive in your HTML document. Both ng-app and data-ng-app are more or less similar inside the <html> document. Ng-model and data-ng-model are also similar. Let’s go again to the question, then whats the difference and why do we need to use two instead of just using one for the purpose.
Certain HTML5 validators will show an error on a property like ng-app but if it has a prefix with data like data-ng-app it will not throw an error. Therefore it is easier to validate your HTML if you use data-ng-app. Angular normalises the element’s tag and attribute name to find which elements match which directive. Typically directives are referred by case-sensitive camelCase normalised name. Since HTML is case-insensitive we use dash-delimited attributes and lower case forms on DOM elements.
Comments
0 comments
Please Sign in or Create an account to Post Comments