0 day streak
javascript / beginner
Snippet

Conditional Content with @if

The @if block is a built-in control flow structure in modern Angular that conditionally renders parts of the template based on a boolean expression.

snippet.js
javascript
1
2
3
4
5
@if (isLoggedIn) {
<button>Logout</button>
} @else {
<button>Login</button>
}
angular
Breakdown
1
@if (isLoggedIn)
Checks if the 'isLoggedIn' property is true; if so, the following content is rendered.
2
@else
Provides an alternative block of HTML to display if the condition evaluates to false.