Reputation: 415
What is the difference between ng-if
and data-ng-if
?
They both seem to work in the same way, however i am not able to figure out the difference in them as not much material is available on data-ng-if
.
Upvotes: 0
Views: 3242
Reputation: 48968
They are equivalent. The $compile
service links them to the same directive.
From the Docs:
The normalization process is as follows:
- Strip
x-
anddata-
from the front of the element/attributes.- Convert the
:
,-
, or_
-delimited name to camelCase.For example, the following forms are all equivalent and match the
ngBind
directive:<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/> </div>
For more informaton, see
Upvotes: 1
Reputation: 338
Upvotes: 0
Reputation: 31
Technically both are same, but while validating your page W3C validator without defining data-
on your custom attribute it will get failed, because W3C validator
doesn't know anything about your custom attribute, so you must have to explicitly define data-
before your custom attribute and then W3C validator
will pass your HTML
Upvotes: 3
Reputation: 5274
arbitary attribute
HTML 5 has introduced data attribute. With the prefix of data- we can create custom data attributes such as
<div id="thediv" data-ng-if="conditino"></div>
Upvotes: 0