#What directives are
A directive is a class that Angular attaches to an element to give it extra behaviour. You don't create directives with new, and you don't call them. You write a selector, add the class to a component's imports, and the compiler attaches a new instance to every element in that component's template that matches the selector. The directive can then read inputs, listen to the element's events, and change the element's properties, classes and styles.
There are three kinds:
| Kind | What it does | Examples |
|---|---|---|
| Component | A directive with its own template — it owns a piece of the view | every @Component |
| Attribute directive | Changes the appearance or behaviour of the element it sits on | NgModel, RouterLink, NgClass, your appHighlight |
| Structural directive | Adds or removes DOM by rendering an <ng-template> zero or more times | NgIf, NgFor, NgSwitch, NgTemplateOutlet |
A useful mental model: a component is a directive plus a view. Everything a directive can do — inputs, outputs, host bindings, lifecycle hooks, injection — a component can do too (see Components vs directives).
What changed in modern Angular is the third row. The everyday structural directives *ngIf, *ngFor and *ngSwitch are replaced by built-in control flow blocks — @if, @for, @switch — that aren't directives at all. They're template syntax the compiler understands directly, so there's nothing to import. NgIf, NgForOf and NgSwitch are marked @deprecated 20.0 in Angular 22's .d.ts files ("Use the @if block instead. Intent to remove in a future major release"). Structural directives as a concept still matter — ngTemplateOutlet, library directives, and every Angular 16 codebase like techStatus use them — which is why this chapter covers both.