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()" },
})- ✓Correct answer: The
hostproperty in the decorator metadata - 2Only
@HostBinding/@HostListener,hostis deprecated - 3
document.querySelector('app-tab')inngOnInit
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.