我的应用程序中有列表,我需要在删除成功时删除项目,但它返回,因此我的项目不会从列表中删除index undefined法典HTML<div *ngIf="groups.length>0"> <ion-item-sliding *ngFor="let group of groups"> <ion-item class="chat-groups"> <ion-avatar slot="start"> <div *ngIf="group.photo != null; else placeholderImage"> <img (click)="openImage(group)" class="gImage" routerDirection="forward" [src]="group.photo"> </div> <ng-template #placeholderImage> <img routerDirection="forward" class="gImage" src="../../assets/placeholders/groups.png"> </ng-template> </ion-avatar> <ion-label routerDirection="forward" [routerLink]="['/tabs/', 'groups', group.id]"> <h2 [innerHTML]="group.name"></h2> <h3 [innerHTML]="group.description"></h3> </ion-label> </ion-item> <ion-item-options side="start"> // index is undefined <ion-item-option color="danger" (click)="leaveGroup(group, $index)">Leave</ion-item-option> </ion-item-options> </ion-item-sliding></div>Componentgroups: any[] = [];leaveGroup(group, index) { this.groupsService.leaveGroup(group.id).subscribe((res: any) => { console.log('group index: ', index); // undefined console.log('group: ', group); // gets the group data console.log('group id: ', group.id); // gets the id this.groups.splice(index, 1); Toast.show({ text: res.message }); });}有什么想法吗?
1 回答
Cats萌萌
TA贡献1805条经验 获得超9个赞
解决
我已经改变了我像这样:*ngFor
*ngFor="let group of groups; index as indexOfelement;"
然后
<ion-item-option color="danger" (click)="leaveGroup(group, indexOfelement)">Leave</ion-item-option>
现在我可以获取项目索引号并将其从列表中删除。
添加回答
举报
0/150
提交
取消