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
What Is the Purpose of the "Role" Attribute in Html
How to Create Links With 'Target="_Blank"' in Markdown
Hide Textfield Blinking Cursor
How to Style Part of an Input Field'S Value
Adding HTML Class Tag Under ≪Option≫ in Html.Dropdownlist
Pseudo Class :Hover Does Not Work in IE7
How to Put Text Over Images in HTML
Why Are Iframes Considered Dangerous and a Security Risk
How to Escape < and > Inside <Pre> Tags
How to Fill a Div with an Image While Keeping It Proportional
Changing the Color of an Hr Element
How to Install a Custom Font on an HTML Site
Why Is My Grid Element'S Height Not Being Calculated Correctly
Why Is There a Vertical Scroll Bar If Parent and Child Have the Same Height
Why Aren't My Bootstrap 4 Columns the Same Height
How to Print Background Images in Ff or Ie
What's the Difference Between HTML 'Hidden' and 'Aria-Hidden' Attributes