Javascript 当我更新时,信息消失了
我正在编写一个代码,用户可以在其中更新一些数据。当用户第一次保存信息时,屏幕上的信息消失。然后,当我第二次单击编辑按钮时,编辑对话框没有打开,我得到下面的错误。有什么问题吗? 下面是编辑对话框组件的HTML和TS的一个小片段:Javascript 当我更新时,信息消失了,javascript,html,angular,typescript,Javascript,Html,Angular,Typescript,我正在编写一个代码,用户可以在其中更新一些数据。当用户第一次保存信息时,屏幕上的信息消失。然后,当我第二次单击编辑按钮时,编辑对话框没有打开,我得到下面的错误。有什么问题吗? 下面是编辑对话框组件的HTML和TS的一个小片段: <div fxLayout="row" fxLayoutAlign="start center"> <mat-form-field appearance="outline
<div fxLayout="row" fxLayoutAlign="start center">
<mat-form-field appearance="outline" fxFlex="100" fxFlex.gt-xs="40" class="w-100-p pr-8">
<mat-label>Receipt Code</mat-label>
<input matInput formControlName="StockIntegrationCode" type="number">
</mat-form-field>
<mat-form-field appearance="outline" fxFlex="100" fxFlex.gt-xs="40" class="w-100-p pr-8">
<mat-label>Receipt Name</mat-label>
<input matInput formControlName="Name" type="text">
</mat-form-field>
</div>
<button mat-stroked-button class="amber-fg pr-4" (click)="save($event)"> Kaydet</button>
你能把你的代码贴在你声明的
setReceiptItems
method/setter的地方吗?错误表明您正在尝试将属性添加到布尔值。我编辑了postNow,显示了您声明receipt
组件成员(this.receipt)的部分。在this.receipt.packagingereipts=receipts行之前,也将其记录到控制台代码>您可能会在那里得到一个布尔值,而不是您所期望的值。除此之外,您还可以将循环替换为let receipts:irecept[]=this.dataSource2.data.map(d=>{return d.receiptas irecept})
也许您的问题在于这一点。\u dialogRef.close(true)代码>尝试此操作。_dialogRef.close(响应)代码>只是在黑暗中射击谢谢你,你是对的问题是这个代码>
save(e) {
e.preventDefault();
if (this.form.valid) {
this.receipt.Name = this.form.controls["Name"].value;
this.receipt.ReceiptType.Id = this.form.controls[
"ReceiptType"
].value;
this.receipt.ReceiptGroupType.Id = this.form.controls["ReceiptGroupType"].value;
this.receipt.StockIntegrationCode = this.form.controls[
"StockIntegrationCode"
].value;
this.confirmDialogRef.componentInstance.confirmMessage =
"Receipt will be changed, are you sure?";
this.confirmDialogRef.afterClosed().subscribe((result) => {
if (result) {
this._productionService
.saveAndGetReceipt(this.receipt)
.subscribe((response: IReceipt) => {
this.receipt = response;
this._messages.Show(
"Receipt is updated",
"SUCCESS",
3
);
this._dialogRef.close(true);
});
}
});
setReceiptItems() {
let receipts: IReceipt[] = [];
for (let d of this.dataSource2.data) {
receipts.push(d.Receipt);
}
let receiptItems: IReceiptItem[] = [];
for (let d of this.dataSource1.data) {
receiptItems.push(d);
}
for (let d of this.dataSourceMuadil.data) {
receiptItems.push(d);
}
let receiptTerms: IReceiptTerm[] = [];
for (let d of this.dataSourceTerm.data) {
receiptTerms.push(d);
}
this.receipt.PackagingReceipts = receipts;
this.receipt.ReceiptItems = receiptItems;
this.receipt.ReceiptTerms = receiptTerms;
}