Ionic 4 ion-item-sliding cannot closed by api

#1

Hi, I am using ion-item-sliding and i want it to be close after i click the button. However i try to use IonItemSliding.close() to close the ion-item-sliding, but it said
ERROR Error: Uncaught (in promise): TypeError: item.close is not a function TypeError: item.close is not a function

Below is my code

//test.html
<ion-item-sliding *ngFor="let item of items">
    <ion-item-options #item side="end">
            <ion-item-option (click)="unread(item.status, item)">click me</ion-item-option>
    </ion-item-options>
</ion-item-sliding>
//test.ts
import { IonItemSliding } from '@ionic/angular';
...
unread(s, item: IonItemSliding){
    console.log(s);
    item.close();

  }

This is my reference from ionic 3

#2

I think you should put the ID in the ion-item sliding not on the ion-item-sliding-option or try to rename your *ngFor variable or the ID.

Hope this helps.

#3

Not sure why but what i did is now added the index and let it be the ID, then the thing is working now.

Maybe related to my item is an object but i also try #item.id but thing is not work with the item id.

Below is the solution for me.

<ion-item-sliding *ngFor="let item of items;  let i = index" #i>