亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

已解決430363個問題,去搜搜看,總會有你想問的

角度指數未定義

角度指數未定義

桃花長相依 2022-09-23 09:14:18
我的應用程序中有列表,我需要在刪除成功時刪除項目,但它返回,因此我的項目不會從列表中刪除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>

現在我可以獲取項目索引號并將其從列表中刪除。


查看完整回答
反對 回復 2022-09-23
  • 1 回答
  • 0 關注
  • 81 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號