I went over this stack overflow discussion. It clearly explains why we need the data
attribute before the Angular directive. I also understand we can use the _
prefix instead of data
, e.g.
<span _ng-bind="qty"></span>
But I have two questions:
1) How does AngularJS know to use data
or _
? In other words, how does the Angular compiler understand this? Are these keywords built in Angular to support the HTML5 specifications?
EDIT:: I got answer for this from the official [Angular JS documentation][2. It is a process called Normalization, whereby it removes the extra word like "data" or "x" or "_" and converts the attribute to an Angular directive.
Angular normalizes an element's tag and attribute name to determine which elements match which directives. We typically refer to directives by their case-sensitive camelCase normalized name (e.g. ngModel).
However, since HTML is case-insensitive, we refer to directives in the DOM by lower-case forms, typically using dash-delimited attributes on DOM elements (e.g. ng-model). The normalization process is as follows:
- Strip x- and data- from the front of the element/attributes.
- Convert the :, -, or _-delimited name to camelCase
2) Suppose, if I already have a huge codebase not following the HTML5 specification, but rather just following the AngularJS directives. Then, is there any tool outside to convert AngularJS directives into HTML5 standards?
Please help me with this second question.