问题
I'm trying to integrate a loading spinner into a button. This also works very well. The problem: If I click on a button, the spinner will respond to every additional button.
How can I correct this?
My code:
<button ion-button block (click)="loading = true">
<ion-spinner class="whiteSpinner" item-left *ngIf="loading" name="bubbles"></ion-spinner>
Buy now - 1,49€
</button>
The other buttons like the same...
Image to show you what I mean:
回答1:
If you have bunch of dynamic buttons you can add unique id to them. Even if you use for example *ngFor
to generate all buttons they will have unique ids different from in this case myButton
.
<button #myButton ion-button block (click)="myButton.loading = true">
<ion-spinner class="whiteSpinner" item-left *ngIf="myButton.loading" name="bubbles"></ion-spinner>
Buy now - 1,49€
</button>
来源:https://stackoverflow.com/questions/52461159/loading-spinner-activates-on-every-button-on-the-page