通过使用模板语句,您的应用程序可以通过显示动态内容或提交表单来与用户互动

与模板表达式类似,模板语句使用类似 JavaScript 的语言。然而,模板语句解析器与模板表达式解析器不同。此外,模板语句解析器特别支持基本赋值(=)和使用分号(;)链接表达式

<button type="button" (click)="onSave($event)">Save</button>
<button type="button" *ngFor="let hero of heroes" (click)="deleteHero(hero)">{{hero.name}}</button>
<form #heroForm (ngSubmit)="onSubmit(heroForm)"> ... </form>
<button (click)="counter = counter + 1; showMessage()">Increase</button>
<p>Counter: {{ counter }}</p>