I am trying to bind dynamic array to md-option. But it is throwing error.
<md-select id="hospital0{{index}}" placeholder="Hospital" style="width:100%; " name="hospital">
<md-option *ngFor="let hospital of hospitalList{{index}}" [value]="hospital.id">{{ hospital.name }}</md-option>
</md-select>
I tried another approach. In that I am fetching the select element and then adding options to it. But it is not adding option inside md-option. This I have tried
public async GetHospitalForCity(cityId: any) {
console.log(cityId);
let ddl = (<HTMLSelectElement>document.getElementById("hospital000"));
let option = document.createElement("option");
option.value = "1";
option.text = "Hospital1";
ddl.appendChild(option);
}
hospitalList{{index}}, because the template expression (with{{}}) will never be parsed. Instead you should use this property inside your component :hospitalList: Array<any[]>, then you can use*ngFor="let hospital of hospitalList[index]"in your template.