Here’s an example:
In the *ngFor directive, register the click response function for the button with the syntax (click)=” function name ()” :
<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>
Copy the code
Click any button to pop up the expected Alert dialog box:
For more of Jerry’s original articles, please follow the public account “Wang Zixi “: