Home > Software design >  How to update an ion-slide after removing an Item?
How to update an ion-slide after removing an Item?

Time:08-18

I have a list of cards in ion-slide, and each card has a close icon to remove it.

    <ion-slides >
                <ion-slide *ngFor="let item of cart; let i = index" >
                    <ion-card>
              
                      <ion-img  src='close.png'    (click)="removeData(item)" ></ion-img>                        
                  </ion-card>
  </ion-slide>
              </ion-slides>

home.page.ts

async removeData(object) {
    .......
      // get the index of object 
this.dataservice.removeItem(index);
        .....
        }

DataServiceService.service.ts

removeItem(index) {
    return this.getAllItems().then((result) => {
      if (result) {
        result.splice(index, 1);
        return this.storage.set('i', result);
      }
    });
  }

When a card is removed, I want the list to be updated or the current page to be refreshed. I tried in the removeItem function "this.router.navigate(["/home"]);" but nothing changed, and "window.location.reload();" reloads all pages starting with login. Could you please suggest a solution to the problem?

CodePudding user response:

It is solved by using splice

   this.cart.splice(index, 1);
  • Related