I created the following simple example component that adds some attributes and listener to the component DOM element using the host property of the @Component decorator. In my c
Here are two different ways to bind a host element class to a property using the @HostBinding
decorator:
@HostBinding('class.enabled') private get isEnabled() { // use getter to reflect external value
return this.selectionService.state.isEnabled;
}
@HostBinding('class.selected') private isSelected = false; // setting this add/removes 'selected' class
constructor(private selectionService: SelectionService) {
this.selectionService.select$.subscribe(isSelected => {
this.isSelected = isSelected;
});
}