>html ~~~ <p>test-event works!</p> <button (click)="run()" >执行事件</button> <p></p> <button (click)="countFunc()" >执行 {{count}} 模板语法</button> <p></p> <button (keydown)="keydown($event)" >监听键盘</button> <textarea>{{keydownString}}</textarea> ~~~ >component.ts ~~~ import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-test-event', templateUrl: './test-event.component.html', styleUrls: ['./test-event.component.css'] }) export class TestEventComponent implements OnInit { constructor() { } ngOnInit(): void { } public count:number=0; public countFunc():void{ this.count+=1; } public keydownString:string=''; public keydown(e):void{ this.keydownString+=e.key; } run():void{ alert('z') } } ~~~