当我们在模板中的子元素上触发 mouseeneter/mouseleave 事件时,有没有办法动态使用@HostBinding,即:
在模板.component.html
<div class="test-btn"
(mouseenter)="mouseenter()"
(mouseleave)="mouseleave()">
</div>
并在 template.component.ts
@HostBinding('class') classes = this.getMouseClass();
在哪里:
private getStateClass() {
const mouse = this.mouseState ? 'mouse-enter' : 'mouse-leave';
return `${mouse}`;
}
mouseenter() {
this.mouseState = true;
}
mouseleave() {
this.mouseState = false;
}