0 day streak
javascript / intermediate
Snippet

Built-in Control Flow

Angular's modern control flow provides a cleaner, more performant alternative to *ngIf. It is built directly into the template compiler, reducing the need for structural directive imports and offering better type checking.

snippet.js
javascript
1
2
3
4
5
6
7
@if (status === 'loading') {
<p>Loading...</p>
} @else if (status === 'error') {
<p>An error occurred.</p>
} @else {
<data-view />
}
angular
Breakdown
1
@if (status === 'loading') {
Initiates a conditional block that only renders if the status is 'loading'.
2
} @else if (status === 'error') {
Handles additional conditions without nesting multiple template tags.