Loading Spinner activates on every button on the page

让人想犯罪 __ 提交于 2020-07-22 04:10:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!