Angular & Signals (283 Qs)•Part 2: HttpClient, RxJS Observables & Angular Elements (36 - 62)
What are the various kinds of directives?
There are mainly three kinds of directives:
- Components — These are directives with a template.
- Structural directives — These directives change the DOM layout by adding and removing DOM elements.
- Attribute directives — These directives change the appearance or behavior of an element, component, or another directive.
Practical Code Example
typescript
// Three Kinds of Directives in Angular:
// 1. Components: Directives with their own template (@Component)
// 2. Structural Directives: Manipulate DOM layout (*ngIf, *ngFor, @if, @for)
// 3. Attribute Directives: Modify appearance or behavior of host element ([ngClass], appHighlight)