Spinner loads for every button when clicked on a specific button

Keyur Hardas

I have implemented an ion spinner and an icon inside a single button which acts as a download button. When the page loads only the download icon is visible and when a user clicks on it the download icon is hidden and the spinner shows up. I have used ngFor to show multiple download buttons.

I am facing an issue when i click on a specific button, all the spinner starts to load rather than the specific button spinner.

Here is my code

          <ion-list>
            <div class="chip" *ngFor="let attachment of Trade.attachment">
              <div class="chip-content">
                <ion-label style="font-weight: 500;">{{attachment.attachment_file_name}}</ion-label>
              </div>
              <div class="chip-close">
                <button  #downloadButton ion-button clear color="dark"
                  (click)="download(attachment.attachment_file_name,attachment.attachment_id,downloadButton.isLoading = true)">
                  <ion-icon name="arrow-down" md="md-arrow-round-down" *ngIf="!downloadButton.isLoading" color="primary"></ion-icon>
                  <ion-spinner class="downloadspinner" name="crescent" *ngIf="downloadButton.isLoading"> </ion-spinner>
                </button>
              </div>
            </div>
          </ion-list>

I have tried the solution from this link. It works but i am not able to stop the spinner when my function is complete.

How do i load a spinner specific to the button?

Shabbir Dhangot

instead downloadButton.isLoading use attachment.isLoading . This will store data in row when button is click

Create one item in attachement as isLoading. Default value will be false. When you click on button make it true and once process is done make it again false.

Change it like below. No need to pass isLoading into function. I have changed it to row instead. With that you can change that particular row value to false.

(click)="download(attachment.attachment_file_name,attachment.attachment_id, attachment);attachment.isLoading = true;"

in your typescript function

download(file, id, attachement_row) {
    //Once your downloading done
    attachement_row.isLoading = false;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Create button spinner when clicked in angular 5

Verify that every button is clicked

change text of a specific button when clicked in React

Output specific JSON when a button is clicked

Set Color in DataBase when specific button clicked

How to retrieve information on a specific button when clicked?

SwiftUI change between 2 texts every time when a button is clicked

How to prompt an action when a button is clicked every three times in flutter

Tkinter when a button is clicked?

Button not responding when clicked

Filtering When a Button is clicked

IndexOutOfRangeException when button is clicked

Overlap when a button is clicked

Button Error When Clicked

How to show spinner in Stripe after button is clicked?

Keep a button disabled every time the form loads

How do I destroy specific button in the loop when clicked?

Hiding a specific table in .net webforms when button is clicked

How to disable sort in datatable when a specific button is clicked

want to get details of a specific user when clicked on button in Angular 4

How to update the image of a specific button when it's clicked on?

How to affect a specific class when button contained in said class is clicked

How to go to specific tab in el-tabs when the button is clicked

Loading Spinner activates on every button on the page

Why does the recyclerview data loads only when the button is clicked the second time

When I click on Login button multiple times It loads the other page same number of times the button is clicked.how can I prevent this?

In angular 4 how can I make a reuseable button component which can enable a spinner when clicked

How to toggle a button when another button is clicked?

Display Content of Button When Button was Clicked