Reputation: 65860
.html
<ion-select-option value="t.result[i].id" *ngFor="let t of (issueTypes$ | async); let i = index ">
{{t.result[i].name}}
</ion-select-option>
.ts
this.issueTypes$ = this.maintenanceService.get();
postman:
{
"result": [
{
"id": "KT5c6wdb8ecd94e",
"name": "Need Batteries"
},
{
"id": "RT5c6aa12600134",
"name": "A/C Not working"
}
]
}
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays. at NgForOf.push../node_modules/@angular/common/fesm5/common.js.NgForOf.ngDoCheck (common.js:3161) at checkAndUpdateDirectiveInline (core.js:22004) at checkAndUpdateNodeInline (core.js:23265) at checkAndUpdateNode (core.js:23227) at debugCheckAndUpdateNode (core.js:23861) at debugCheckDirectivesFn (core.js:23821) at Object.eval [as updateDirectives] (MaintenancePage.html:19) at Object.debugUpdateDirectives [as updateDirectives] (core.js:23813) at checkAndUpdateView (core.js:23209) at callViewAction (core.js:23450)
Can you tell me the issue here?
Upvotes: 1
Views: 4460
Reputation: 2671
The problem is that you are trying to iterate over the result object. You need to go a level deeper. So change your code to below:
<ion-select-option value="t.id" *ngFor="let t of (issueTypes$ | async)?.result; let i = index ">
{{t.name}}
</ion-select-option>
Upvotes: 0
Reputation: 62213
Based on your json model from postman you should iterate over the result
property which is the array in the returned model.
*ngFor="let t of (issueTypes$ | async)?.result; let i = index"
Then inside the containing html can access t
directly which contains the object from the array. The index variable i
is also no longer necessary.
{{t.name}}
Upvotes: 2