javascript / beginner
Snippet
Conditional Rendering with *ngIf
The *ngIf directive is used to conditionally include or remove an HTML element from the DOM based on a boolean value.
snippet.js
1
2
3
4
5
6
export class StatusComponent {isLoggedIn: boolean = true;}<!-- Template --><p *ngIf="isLoggedIn">Welcome back, user!</p>
angular
Breakdown
1
isLoggedIn: boolean = true;
A boolean property that tracks the user's login status.
2
*ngIf="isLoggedIn"
A structural directive that adds the element to the DOM only if isLoggedIn is true.