Skip to main content

Built-in directives

Learn Built-in directives (Module 6 · Directives, Angular) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

What are directives? • A directive is a class that teaches an HTML element new tricks, like a sticker that says "turn red on hover". Angular has three directive types : • Component directives : a directive with a template (every component is one). • Attribute directives : change appearance or behaviour of an existing element (ngClass, ngStyle, ngModel). • Structural directives : add or remove elements from the DOM (the legacy *ngIf, *ngFor; today replaced by @if and @for control flow).

More lessons in Module 6 · Directives