数据可视化我爱编程Angular

Angular事件绑定

2018-04-15  本文已影响15人  readilen

目前Angular 5 支持的事件

(focus)="myMethod()"  // An element has received focus
(blur)="myMethod()"   // An element has lost focus

(submit)="myMethod()"  // A submit button has been pressed

(scroll)="myMethod()"

(cut)="myMethod()"
(copy)="myMethod()"
(paste)="myMethod()"

(keydown)="myMethod()"
(keypress)="myMethod()"
(keyup)="myMethod()"

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

(click)="myMethod()"
(dblclick)="myMethod()"

(drag)="myMethod()"
(dragover)="myMethod()"
(drop)="myMethod()"

組件模板中的使用方法

<button (click)="myEvent($event)">My Button</button>

組件中

export class AppComponent {
  
  myEvent(event) {
    console.log(event);
  }

}

事件类型一览表

上一篇下一篇

猜你喜欢

热点阅读