Directives are what Angular uses to connect to the Document Object Model (DOM). This allows Angular to separate the concerns of what each part of the application should do. This means that a controller should never touch the DOM. A controller should only work through directives to change the DOM.


When using directives, Angular must parse the DOM and figure out what directives apply to it. This is done by normalizing all the elements and tags. Normalization will remove any ";" "," " -", or" _". It will also remove x- and data- from the beginning of any attributes. For example, when looking for ngModel, all of the following will match:

  • x-ng:model
  • data-ng_model
  • ng-model
  • ng:model


If you are concerned with HTML 5 validation, ...

Get Web Developer's Reference Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.