Angular · Junior · Question 18 of 75

How do you conditionally render a block in modern Angular templates?

@if (user) {
  <p>Hello, {{ user.name }}</p>
} @else {
  <p>Please sign in</p>
}

Explanation

Built-in control flow (@if, @for, @switch) has been stable since Angular 17. It needs no imports and is faster than the older *ngIf/*ngFor structural directives.

Further reading

Problem with a question

Angular · Junior · question 18

Test yourself

Take the Angular · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz