【发布时间】:2020-04-09 09:59:46
【问题描述】:
在我的编辑表单中,我无法检索在添加时存储的值。 流程就像选择第一个选择框的一个选项后,它的相关数据将显示在下一个选择框中。
我已经为选定的值尝试了这个answer,但没有显示这些值。
我的表格如下:
<form [formGroup]="productForm" (ngSubmit)="onSubmit()">
<mat-form-field">
<mat-label>Main Type</mat-label>
<mat-select [(value)]="selectedType" (selectionChange)="onTypeChange($event.value)"
formControlName="mainTypeId">
<mat-option *ngFor="let list of mainList" [value]="list.id">{{list.name}}</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field">
<mat-label>Sides Type</mat-label>
<mat-select [(value)]="selectedSide" formControlName="sideTypeId">
<mat-option *ngFor="let list of sidesList" [value]="list.id">{{list.name}}
</mat-option>
</mat-select>
</mat-form-field>
</form>
EditProductComponent.ts
export class EditProductUploadImageComponent implements OnInit {
public selectedType: any;
public selectedSide: any;
constructor(private fb: FormBuilder,
private productService: ProductService) {
this.formInitialization();
this.getSelectedData()
}
getSelectedData() {
this.productService.getProductDesignRef(this.data.editId).subscribe((response: any) => {
this.refrences = response.data[0]
console.log(this.refrences)
this.productService.getMainListById(this.refrences.main_type_id).subscribe((response: any) => {
this.selectedType = response.data[0].id
this.getMainTypeList()
if(response) {
this.productService.getSidesListById(this.refrences.sides_type_id).subscribe((response: any) => {
this.selectedSide = response.data[0].id
this.onTypeChange(1)
})
}
})
})
}
getMainTypeList() {
this.productService.getMainTypeList().subscribe((response: any) => {
if (response) {
this.mainList = response.data;
console.log(this.mainList)
}
}
}
onTypeChange(value: number) {
this.productService.getSidesTypeListById(value).subscribe((response: any) => {
if (response) {
this.mainTypeListById = response['data']['0']['sides-type'];
this.sidesList = this.mainTypeListById
console.log(this.sidesList)
}
}
}
}
=> 通过使用参考 ID,我在表单中传递了一个选定的值。但无法获得正确的输出。
请查看此jsfiddle link 中的所有控制台日志
如需更多说明,请查看这两张关于工作流程的图片。
- 记录列表:https://prnt.sc/rw2ucu;单击编辑按钮时,将打开一个编辑窗口,我希望列表页面中列出的两个值用于更新记录。
- 编辑对话框:https://prnt.sc/rw2xeh
提前谢谢...!!!
【问题讨论】: