ionic-framework: [Ionic V4.0.0-beta.7] [ion-item-sliding] Sliding not working after empty an element in array
Bug Report
Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.
Ionic:
ionic (Ionic CLI) : 4.1.2 (C:\Users\fkrishna\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : @ionic/angular 4.0.0-beta.7
@angular-devkit/core : 0.7.5
@angular-devkit/schematics : 0.7.5
@angular/cli : 6.1.5
@ionic/ng-toolkit : 1.0.8
@ionic/schematics-angular : 1.0.6
System:
NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)
npm : 5.6.0
OS : Windows 10
Describe the Bug I created an array of 3 elements and i used the <ngFor> and the <ion-item-sliding">directive to show a list of sliding item. Each item has a remove button to remove the target element, but after removing one element the sliding stop working for the remaining items
Steps to Reproduce Steps to reproduce the behavior:
- Go to ‘…’
- Click on ‘…’
- Scroll down to ‘…’
- See error
Related Code
<ion-content>
<ion-list>
<ion-item-sliding *ngFor="let n of numbers; index as i">
<ion-item>
{{ n }}
</ion-item>
<ion-item-options>
<ion-item-option " (click)="remove(i)">Delete</ion-item-option>
</ion-item-options>
</ion-item-sliding>
</ion-list>
numbers = ['1','2','3'];
constructor() {}
remove(i) {
this.numbers.splice(i, 1);
}
Expected Behavior the sliding is suppose to work correctly for each items even after removing an element
Additional Context List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, screenshots, OS if applicable, etc.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 30 (5 by maintainers)
Also had the same issue, with a dynamic list of elements, deleting an item with the <ion-item-sliding> component, then refreshing the elements cause it not to be able to delete any other elements until a refresh.
After digging around i noticed that without the refresh of elements it worked fine, looking at the docs there is a method to close all sliding items on the item or on the list. using this fixed the issue.
#dynamicList@ViewChild('dynamicList') dynamicList;<ion-item-option>triggering thedynamicList.closeSlidingItems()before deleting the record.Hope this helps in the meantime, i am new to angular so hopefully i am not doing anything that stupid.
not all heroes wear capes, thx @jcollings for the solution!
html:
ts:
I found that another workaround is to pass the reference to the ItemSliding to the delete method and then just closing that one item before deleting the list item:
HTML:
TS:
I got the same issue. By the way, the sliding items are not working after delete one, need to reload the app
Thanks for this issue! This has been merged in by PR #17492. It will be in the next release:
4.1.0. Please let us know if you are still seeing problems after that.I’ve donne this : in .html
works perfectly Many thanks to @jcollings.
This bug still exist in 4.0.0-rc.2. I use a ion-item-sliding inside virtual-scroll, so I can’t use List.closeSlidingItems(). If I don’t close a item sliding and leave the view using back button or something, then the item sliding stop working next time at all. I can’t use (click) event in this case because I open the sliding and just leave. There is no change to catch (click) event.
Another workaround. It works for me.
@bockoblur: I checked out your Stackblitz example and played around with it for a bit. If you actually delete the items from the list, the workaround seems to work fine. If they are merely hidden and then shown again, the behavior is exactly as you described. This seems to be an issue with the transform: translate not being correctly applied to the list item element. Maybe the ItemSliding component still uses the old DOM reference to translate the item. You can find my modified example here: https://stackblitz.com/edit/ionic-4-item-sliding-show-hide-error-zxgbmf
This issue is obviously a bug. Remove an item should not need to close it before deleting, it’s funny.
@Anthony2539 probably a bit of both 😜
I don’t know if it’s a feature request or a bug
Some commit regarding slidings have been made recently I think, so maybe the problem is/will disappear
Anyhow, let’s say that workaround works and won’t arm my app I guess
@quynh-ng I have the same issue, i’ve had to downgrade to beta.5 😦