I have a element in component.html:
<select name="select1">
<option *ngFor="let option of optionsArr">{{option}}</option>
</select>
Inside component.ts, I am populating optionsArr from Excel:
export class ComponentX implements OnInit {
optionsArr = [];
constructor(private service : ServiceX) {
}
ngOnInit() {
this.service.getJSON(filepath).subscribe((jsonObj:any)=> {
for (var x in jsonObject){
this.optionsArr.push(x);
}
});
}
In service.ts
export class ServiceX {
constructor() {}
getJSON(filepath){
return Observable.create((observer:any) =>{
//retrieve JSON here
observer.next(jsonObj);
observer.complete();
});
}
}
But clicking the drop down, nothing appears. I am guessing the view has been loaded before optionsArr has been populated. So my question is, is there a way around this?