sách gpt4 ăn đã đi

javascript — Xóa các mục khỏi *ngFor khỏi *ngFor bằng Angular

In lại 作者:搜寻专家 更新时间:2023-10-30 22:05:17 27 4
mua khóa gpt4 giày nike

我想从 *ngFor 中删除 *ngFor 中的项目。

nhập mô tả hình ảnh ở đây

当我删除回复“test2”时,

nhập mô tả hình ảnh ở đây

在我添加其他回复后,“test3”变为空。

nhập mô tả hình ảnh ở đây









<đầu>

Id
Text
Action







id="{{indexContent}}-{{indexMessage}}-{{indexReply}}-reply-text"
[(ngModel)]=content.messages[indexMessage].replies[indexReply].text
name="[[indexContent]]-[{{indexMessage}}]-[{{indexReply}}]-reply-text">





Remove Reply









Add Reply








我的消息模型具有添加回复、删除回复的不同功能

message.model.ts

import { Reply } from "./reply";

export class Message {

constructor(public id: number = 0,
public text: string = '',
public replies: any[] = []) {
}

public setModel(obj) {
Object.assign(this, obj);
}

addReply(new_reply) {
this.replies.push(new_reply);
}

addNewReply() {
let new_reply = new Reply();

this.replies.push(new_reply);
}

removeReply(reply) {
this.replies.splice(this.replies.indexOf(reply), 1);
}
}

我在这里重现了我的问题:Remove object from array in *ngFor in Angular

https://stackblitz.com/edit/angular-clmi7d

câu trả lời hay nhất

tôi sẽ sử dụng trackBy 选项来避免 unexpected situations

html

 
 

关于javascript - 使用 Angular 从 *ngFor 中删除 *ngFor 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47696165/

27 4 0
Chứng chỉ ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com
Xem sitemap của VNExpress