Angular 2 Hover event

前端 未结 9 1158
深忆病人
深忆病人 2020-12-02 06:20

In the new Angular2 framework, does anyone know the proper way to do a hover like an event?

In Angular1 there was ng-Mouseov

9条回答
  •  暖寄归人
    2020-12-02 06:54

    If you want to perform a hover like event on any HTML element, then you can do it like this.

    HTML

     

    Div A

    Div B

    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 inorder to implement fully functional hover events in angular 2.

提交回复
热议问题