从ngModel获取值并将其存储在对象中



我正在我的应用程序中进行内联编辑,我从API获取数据并使用ngModel将值存储在输入中,我有自定义对象(editCat和editCarSub(,我想将其发送到API,我想从输入中获取值并将其存储在我的对象中,我如何实现这一点?

这是我的堆叠式

.ts

done(id, index) {
this.editCat = {
carPartCategoryId: id,
name: '', //input value here
};
this.hidemeSub[index] = false;
console.log(this.editCat);
}

.html

<div *ngFor="let item of items; let index = index">
<div class="d-flex align-items-center">
<span [hidden]="hidemeSub[index]">{{ item.name }}</span>
<div
class="btn"
(click)="hidemeSub[index] = !hidemeSub[index]"
[hidden]="hidemeSub[index]">
Edit
</div>
</div>
<div class="d-flex pl-3">
<input type="text" [hidden]="!hidemeSub[index]" [(ngModel)]="item.name" />
<div
class="btn"
[hidden]="!hidemeSub[index]"
(click)="done(item.carPartCategoryId, index)">
Done
</div>
</div>
</div>

在完成的功能中传递项目名称

(click)="done(item.carPartCategoryId, item.name, index)"

然后

done(id, name, index) {
this.editCat = {
carPartCategoryId: id,
name: name, //input value here
};
this.hidemeSub[index] = false;
console.log(this.editCat);
}

最新更新