What are directives in Angular7?

In Angular7, directives are used to add behavior to an existing DOM element or an existing component instance.

In Angular 7, directives are a type of component that extends the functionality of HTML elements in the DOM (Document Object Model). They allow you to attach behavior to elements or transform the structure of the DOM. There are three types of directives in Angular:

  1. Component Directives: These are the most common type of directive in Angular. Components are directives with a template.
  2. Structural Directives: These directives change the structure of the DOM by adding, removing, or manipulating elements. Examples include *ngIf, *ngFor, and *ngSwitch.
  3. Attribute Directives: These directives change the appearance or behavior of an element, component, or another directive. Examples include ngStyle, ngClass, and ngModel.

Directives are essential in Angular development for creating reusable components, enhancing the functionality of existing components, and providing a way to interact with the DOM.