Angular 2 Hover event

前端 未结 9 1146
深忆病人
深忆病人 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:34

    In your js/ts file for the html that will be hovered

    @Output() elemHovered: EventEmitter = new EventEmitter();
    onHoverEnter(): void {
        this.elemHovered.emit([`The button was entered!`,this.event]);
    }
    
    onHoverLeave(): void {
        this.elemHovered.emit([`The button was left!`,this.event])
    }
    

    In your HTML that will be hovered

     (mouseenter) = "onHoverEnter()" (mouseleave)="onHoverLeave()"
    

    In your js/ts file that will receive info of the hovering

    elemHoveredCatch(d): void {
        console.log(d)
    }
    

    In your HTML element that is connected with catching js/ts file

    (elemHovered) = "elemHoveredCatch($event)"
    

提交回复
热议问题