看个例子:
在*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对话框: