W3C validation with AngularJS directives

AndyB picture AndyB · Jun 5, 2013 · Viewed 14.6k times · Source

How do we go about doing W3C validation with an Angular application?

Since custom directives make for invalid HTML validation, we typically see lots of W3C validation errors. Are there any strategies for this?

Answer

rewritten picture rewritten · Jun 5, 2013

Strict w3c validation allows any data-* attributes, and any class.

Directives can be applied to DOM elements with any of:

  1. <tag directive-name>
  2. <tag data-directive-name> (*)
  3. <tag x-directive-name>
  4. <tag directive_name>
  5. <tag x_directive_name>
  6. <tag data_directive_name>

At least the data- one is fully W3C compliant (provided you declare HTML5 doctype). So the following code validates (the attribute name, of course it fails for missing title, missing encoding etc):

<!DOCTYPE html>
<html>
 <body data-ng-app="MyApp">
 </body>
</html>