I have left panel that has form control fields, based on p-dropdown selection , I am updating the right panel content. On page load I am trying to show default values on dropdowns but due to form arrays not updating, the I am not able to see the default values on p-dropdown. Can some please help?
ngOnInit(): void {
this.formcopy = this.fb.group({
scenariotype: [null],
case: [ null]
});
this.getCaseNames();
this.loadScenarioData(this.scenarioId);
}
getCaseNames(){
this.globalparaService.getParam('27e1423a-0d12-1213-b113-aace6639ae08').subscribe((res) => {
res.data.Case.map(obj => {
this.caseName.push({ name: obj.CaseName, code: obj.CaseName });
});
});
}
loadScenarioData(scenarioId) {
this.service.getScenarioByScenarioId(scenarioId).subscribe((res) => {
this.populateFormdata(res.data);
});
}
populateFormdata(data){
this.formcopy.patchValue({
scenariotype: ['Low'],// not updating even though using hardcoded value
case: [ 'P50']// same here , FE not updating these values
});
<form [formGroup]="formcopy">
<p-dropdown [options]="scenario" (onChange)="setScenarioType($event)" optionLabel="name" optionValue="code"
formControlName="scenariotype" ngDefaultControl ></p-dropdown>
<p-dropdown [options]="caseName" (onChange)="setCaseName($event)" optionLabel="name" optionValue="code"
formControlName="case" ngDefaultControl></p-dropdown>
</form>