看個例子:
在*ngFor指令内,使用文法(click)="函數名()"的方式給button按鈕注冊click響應函數:
<h2>Products</h2>
<div *ngFor="let product of productsJerry2">
<h3>
<a [title]="product.name + ' details'">
{{ product.name }}
</a>
</h3>
<p *ngIf="product.description">
Description: {{ product.description }}
</p>
<button (click)="share()">
Share
</button>
</div>
點選任意的button,彈出期望的alert對話框: