DOM manipulation is not always best handled in components. Components should be as lean as possible; this way, things are kept simple and your code can easily be moved around and reused. So, where should we handle DOM manipulation then? The answer is directives. Just like you should take data manipulation tasks to services, best practices suggest you take heavy DOM manipulations to directives.

There are three types of directives in Angular:

  • Components
  • Attribute directives
  • Structural directives

Yes, components! Components are qualified directives. They are directives with a direct access to the template being manipulated. We have already seen components enough in this book; let's focus on the attribute and structural directives. ...

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.