1

After I saw Angular syntax. I always wonder if it is valid html and conform to html spec.
After reading through some posts and articles there are 2 sides of opinions.

One said that it is valid according to the syntax spec. 1
Another said no! The attribute of each HTML tag is predefined in a certain specific set with some exception such as data attribute. (e.g. 2, 3)

There are more frameworks apart from angular that invent this kind of new attributes. Some of them (e.g. jsx) compile custom syntax into valid javascript or html representation of the template.
Some of them (e.g. Angular itself) use it as is (or at least use it as is for some short period of time).

The point of this question is not all about Angular but for the convenience of answering lets scope it down to just Angular.

Is the syntax valid according to every part of the specification?
Does Angular use another method that somehow makes the syntax valid? (e.g. there is another part of spec that allow extending the spec itself anyhow.)
If no positive answer to the questions above why it is widely used?

Community
  • 1
  • 1
Curious Sam
  • 884
  • 10
  • 12
  • 1
    Simple answer is can use `data-` prefix for any angular attribute and make it totally valid – charlietfl Sep 29 '15 at 16:48
  • @charlietfl Did you see new event binding syntax in Angular 2? – Curious Sam Sep 29 '15 at 16:51
  • if you don't use the `data-` prefix, then no, it is not valid HTML according to any doctype, but who cares anyway? It _is_ valid HTML (provided you follow attribute naming restrictions), it's just not valid to a doctype-specific HTML spec to validate on. it's still well-formed and works in all browsers. – dandavis Sep 29 '15 at 17:01
  • 1
    @dandavis I do care. The standard is there for reasons. There is nothing guarantee that the attributes will be support by all browsers. If there is just only 1 browser that not support these attributes the culprit is Angular not the browser. This is one role of the standard. It is exist to pin point who or which component should be change. – Curious Sam Sep 30 '15 at 09:07
  • @CuriousSam: w/angular, if you're worried about it, you can use the data- flavors and validate as HTML5. That said, angular is for apps and it doesn't work in all browsers anyway. validation was more important in the past when there were rendering quirks between browsers (no more w/HTML5) and we were worried about consistently presenting documents (no more w/ responsive design). i'm not saying it's useless, but validation doesn't provide the bang for the buck it used to, so it's importance as a criterion of quality has diminished. – dandavis Sep 30 '15 at 19:14

0 Answers0