I have a simple data model where a study has many samples. I set the p-dropdown's options, ngModel, and optionLabel during the ngOnInit method of the control:
<p-dropdown [options]="samples" [(ngModel)]="selectedSample" optionLabel="name"></p-dropdown>
In the component's ngOnInit method, I listen for study changes and then populate the dropdown with the samples of that study. This works perfectly on the load of the page:
this.study$.subscribe((study)=>{
this.selectedStudy = study;
this.selectedSample = null;
this.samples = study.samples;
this.selectedSample = study.samples.filter(f => f.sampleId == study.selectedSample.sampleId)[0];
}
});
When an event is raised from another control that would change the study, I have stepped through this code and see that the samples get correctly assigned and that the selectedSample is correctly assigned as well. But the p-dropdown is still showing the first value of the dropdown and not the actual selected value.
Why doesn't primeNg's dropdown work on the second time I set the values?