What is a directive? What are the types?

Angular directives, pipes and DI · Freshers

Model answer

A directive adds behaviour to an element in a template. There are three kinds. Components are directives with a template. Structural directives change the DOM structure by adding or removing elements, such as the older *ngIf and *ngFor. Attribute directives change how an element looks or behaves, such as ngClass, ngStyle or your own custom directive.

You create a custom one with the @Directive decorator and a selector, for example to highlight an element when the mouse is over it.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions