I have a dropdown in my component. Here is the code of the component:
export class MyComponent {
MyObjectArray: MyObject[] = [];
constructor(private _service: MyService)
}
ngOnInit() {
this._service.get().do((response): MyObject[]) => {
this.MyObjectArray = response;
this.MyObjectArray.forEach((obj) => {
console.log(obj.Code)
});
});
My html is:
<select>
<option [value]="obj.Code" *ngFor="let obj of MyObjectArray; let i = index">{{obj.Code}}</option>
</select>
And in my service:
return this._http.get(_url, this.options)
.map(res => res.json())
.catch(super.handlerError);
I have a console.log in my code to verify that the service returned something and I am having results. The issue is why is it not binding on my dropdown. I did inspect element and there are no items in my dropdown.
Oh and one thing, I tried putting the ngFor in a div with span inside, it was working. I just don't understand when I put it on my dropdown it doesn't work.
EDIT
Now when I inspect element, I can see my objects. But they are still not appearing in my dropdown. Here is what I changed:
this._service.get().subscribe(response => this.MyObjectArray = response);
EDIT
I also have this code on my ngAfterViewInit()
$('select').material_select();