我在我的應用程式中進行行內編輯,我從 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>
uj5u.com熱心網友回復:
在完成函式中傳遞專案名稱
(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);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/431910.html
