Angular Directives
Directives in Angular are instructions added to the DOM, which modify the appearance or behavior of elements. There are two main types of directives: structural and attribute directives.
Structural Directives:
Structural directives change the layout by adding or removing elements from the DOM.
<div *ngIf="isLoggedIn">Welcome, User!</div>
ngFor Directive:
<ul>
<li *ngFor="let item of items">{{ item }}</li>
</ul>
ngSwitch Directive:
<div [ngSwitch]="userRole">
<p *ngSwitchCase="'admin'">Admin View</p>
<p *ngSwitchCase="'user'">User View</p>
<p *ngSwitchDefault>Guest View</p>
</div>
Attribute Directives:
Attribute directives change the appearance or behavior of an existing element.
<div [ngClass]="{ 'active': isActive }">This is a dynamic class example.</div>