This question was asked many times and couldn't help me with my problem. Not sure whats wrong with the approach and hope some fresh "eyes"
Here is my dropdownlist binding in HTML: I am binding programName which is a string to both value and text properties.
<select [ngModel]="selectedObject">
<option *ngFor="let p of programs" value= {{p.programName}}>
{{p.programName}}
</option>
</select>
In my .ts file, here is the what i am doing to bind the default value to the "select"
loadData(pList: IProgram[]) {
this.programs = pList;
if (this.programs.length > 0) {
this.selectedObject = this.programs[0];
}
}
The data is binding to "select" properly,
- but the default value is showing as empty text, where i need to click and select an value.
- Another issue is when i change the dropdown value from A to B, the "selectedObject" value is always giving me "A" instead of "B". As it is [ngModel], two way binding would take care. But, its not happening as i might be missing something here.
Can someone help whats the problem with this approach?