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 into the module where the component fits. This was automatically done by angular-cli when generating the application within the app.module.ts
file:
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core...