Angular · Middle · Question 45 of 75

What is the recommended way to bind to the host element of a component?

@Component({
  selector: "app-tab",
  host: { role: "tab", "[class.active]": "active()", "(click)": "select()" },
})

Explanation

The Angular style guide prefers the host object over the @HostBinding/@HostListener decorators: everything about the host is in one place and the expressions are type-checked.

Further reading

Problem with a question

Angular · Middle · question 45

Test yourself

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

Take this quiz