Core directives

If you are familiar with Angular 1.x, you already know what a directive is. If not, here is a quick definition: a directive is a custom attribute that adds functionality to an element. In Angular, a component is considered to be a special case of a directive which contains a template.

Angular 2 core includes several directives—NgClass, NgFor, NgIf, NgStyle, NgSwitch, NgSwitchWhen, and NgSwitchDefault.

If you are familiar with Angular 1, you already know what these directives can do, although the syntax and the underneath implementation have been changed.

Those directives aim to help us implement common templating tasks such as DOM manipulation.

To be able to use core directives in a component, we need to import the BrowserModule module ...

Get Angular 2 Components 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.