Angular 2 Hover event

前端 未结 9 1170
深忆病人
深忆病人 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 07:00

    If the mouse over for all over the component is your option, you can directly is @hostListener to handle the events to perform the mouse over al below.

      import {HostListener} from '@angular/core';
    
      @HostListener('mouseenter') onMouseEnter() {
        this.hover = true;
        this.elementRef.nativeElement.addClass = 'edit';
      }
    
      @HostListener('mouseleave') onMouseLeave() {
        this.hover = false;
        this.elementRef.nativeElement.addClass = 'un-edit';
      }
    

    Its available in @angular/core. I tested it in angular 4.x.x

提交回复
热议问题