Coder Perfect

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


I’m now watching this angular start tutorial video. js

The speaker says that the attributes ng-app=”” and data-ng-app=”” are more or less equivalent inside the html> tag, as are ng-model=”my data binding” and data-ng-model=”my data binding” at some point (after 12’40”). However, the speaker claims that depending on which property is utilized, the html will be evaluated using multiple validators.

Could you clarify the difference between the two approaches, ng- and data-ng- prefixes?

Asked by Stephane Rolland

Solution #1

That is an excellent question. The distinction is simple: there is no difference between the two except that some HTML5 validators will throw an error on a property like ng-app, but not on anything prefixed with data-, such as data-ng-app.

To address your question, if you want to make verifying your HTML a little easier, utilize data-ng-app.

Fun fact: You can achieve the similar effect using x-ng-app.

Answered by Code Whisperer

Solution #2

From Angularjs Documentation

All of the directions listed below are valid based on the aforesaid assertion.

ng-bind is the first. ng:binding 3. the ng bind function data-ng-bind is number four. 5. x-ng-bind x-ng-bind x-ng-bind x

Answered by srinu

Solution #3

Custom data-*attributes are valid in the HTML5 specification, which is where the difference resides. You should use them instead of the ng attributes if you need your markup to be validated.

Answered by Manu Clementz

Solution #4

The terms ng-model and data-ng-model are interchangeable.

<div ng-controller="Controller">
  Hello <input ng-model='name'> <hr/>
  <span ng-bind="name"></span> <br/>
  <span ng:bind="name"></span> <br/>
  <span ng_bind="name"></span> <br/>
  <span data-ng-bind="name"></span> <br/>
  <span x-ng-bind="name"></span> <br/>

Answered by Eddy

Solution #5

If you want to make your page HTML valid, you can use data-ng- instead of ng-.

Answered by NNaseet

Post is based on