Angular 2 Hover event

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

    yes there is on-mouseover in angular2 instead of ng-Mouseover like in angular 1.x so you have to write this :-

    hello mouseover
    over(){ console.log("Mouseover called"); }

    As @Gunter Suggested in comment there is alternate of on-mouseover we can use this too. Some people prefer the on- prefix alternative, known as the canonical form.

    Update

    HTML Code -

    hello mouseover

    Controller/.TS Code -

    import { Component } from '@angular/core';
    
    @Component({
      selector: 'my-app',
      templateUrl: './app.component.html',
      styleUrls: [ './app.component.css' ]
    })
    export class AppComponent  {
      name = 'Angular';
    
      over(){
        console.log("Mouseover called");
      }
    
      out(){
        console.log("Mouseout called");
      }
    }
    

    Working Example

    Some other Mouse events can be used in Angular -

    (mouseenter)="myMethod()"
    (mousedown)="myMethod()"
    (mouseup)="myMethod()"
    

提交回复
热议问题