If you want to perform a hover like event on any HTML element, then you can do it like this.
HTML
<div (mouseenter) ="mouseEnter('div a') " (mouseleave) ="mouseLeave('div A')">
<h2>Div A</h2>
</div>
<div (mouseenter) ="mouseEnter('div b')" (mouseleave) ="mouseLeave('div B')">
<h2>Div B</h2>
</div>
Component
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'basic-detail',
templateUrl: 'basic.component.html',
})
export class BasicComponent{
mouseEnter(div : string){
console.log("mouse enter : " + div);
}
mouseLeave(div : string){
console.log('mouse leave :' + div);
}
}
You should use both mouseenter
and mouseleave
events in order to fully implement functional hover events in angular 2.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…