Angular · Junior · Question 74 of 75

How do you show a button only to admins and a label to everyone else?

@if (user().isAdmin) {
  <button>Delete</button>
} @else {
  <span>Read only</span>
}

Explanation

@if removes the elements from the DOM. Hiding UI is not security - the server must also check permissions.

Further reading

Problem with a question

Angular · Junior · question 74

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