【发布时间】:2020-08-13 08:33:55
【问题描述】:
更新表单时,我使用补丁值在表单中显示创建的数据,我能够在所有表单字段中显示创建的数据,但一个字段除外。我还使用 setValue 来显示该特定的数据字段,但它不起作用,任何人都可以提供解决方案。 这是代码 ts
public addMaterialForm = this.fb.group({
barcodes:[],
labelSpecs:[],
labelSize: [''],
})
ngOnInit() {
this.receiptSrv.currentSharedMaterial.distinctUntilChanged().subscribe(data => {
if (data) {
this.addMaterialForm.patchValue(data);
this.editMode =true;
}
});
}
html
<!-- Label Size -->
<div fxLayout="row">
<mat-form-field>
<mat-label>Barcodes Size</mat-label>
<mat-select formControlName="labelSize" required>
<mat-option *ngFor="let barcode of barcodes" [value]="barcode">
Barcodes Size- {{barcode.height}} X {{barcode.width}}
</mat-option>
</mat-select>
<mat-error *ngFor="let labelSizeMsg of materialInfoValMsg.labelSize">
<mat-error class="error-message" *ngIf="addMaterialForm.get('labelSize').hasError(labelSizeMsg.type) &&
(addMaterialForm.get('labelSize').dirty || addMaterialForm.get('labelSize').touched)">
{{labelSizeMsg.message}}
</mat-error>
</mat-error>
</mat-form-field>
</div>
这是来自后端的响应
labelSize: "{"createdAt":null,"modifiedAt":null,"createdBy":null,"modifiedBy":null,"id":"641a55d1-1026-4093-b339-02174b09891a","height":1,"width":1}"
我需要在 barcodeSize-1X1 这样的表单的 barcodeSize 字段中显示宽度和高度。
【问题讨论】:
标签: html angular typescript angular-material