I have the object Categories(id, name), I get like this on Angular:
this.categories = new Array<Category>(); this.http .get(ApiConfig.API_URL + 'getCategories') .toPromise() .then(response => this.categories = response.json()) .catch(_ => console.log("error getting categories")); The object Categories.ts:
export class Category { constructor( public id: string, public name: string) { } } And I am trying to put them as options on autocomplete field like this:
<div> <md-form-field> <input type="text" mdInput [mdAutocomplete]="auto"> </md-form-field> <md-autocomplete #auto="mdAutocomplete"> <md-option *ngFor="let category of categories"> {{ category.name }} </md-option> </md-autocomplete> </div> But I get the following error
Error trying to diff '[object Object]'. Only arrays and iterables are allowed
I tried with
<md-option *ngFor="let category of categories" [value]="category.id" [label]="category.name"> But it still throwing the same error, what am I doing wrong?
.then(response => this.categories = response.json())to.then(response => { this.categories = response.json(); console.log(%O, this.categories); })and show us the output?