В моей форме редактирования я не могу получить значения, которые хранятся во время добавления. Процесс подобен тому, когда выбирается опция первого поля выбора, после чего его соответствующие данные будут отображаться в следующем окне выбора.
Я пробовал ответить для выбранного значения, но значения не отображаются.
У меня есть форма, как показано ниже:
<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)
}
}
}
}
=> Используя идентификаторы ссылок, я передал выбранное значение в форме , Но не может получить правильный вывод.
Просьба просмотреть все журналы консоли в этой jsfiddle link
Для получения дополнительной информации просмотрите эти два изображения, касающиеся рабочего процесса.
- Список записи: https://prnt.sc/rw2ucu; при нажатии на кнопку редактирования откроется окно редактирования, и я хочу, чтобы два перечисленных значения были на странице списка для обновления записей.
- Диалоговое окно редактирования: https://prnt.sc/rw2xeh
Заранее спасибо ... !!!