0
I am trying to display a list using ngFor but is giving this error: ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
Can someone tell me why?
Json:
{
result:{
_id:"5be5c978dec9a11c0cba3d45",
date:"2018-11-16T02:00:00.000Z",
dayOfWeek:"Friday",
times:[
{
name:"a",
hourInit:"06:00",
_id:"5be5c978dec9a11c0cba3d54"
},
{
name:"b",
hourInit:"07:00",
_id:"5be5c978dec9a11c0cba3d53"
},
{
name:"c",
hourInit:"08:00",
_id:"5be5c978dec9a11c0cba3d52"
}
]
}
}
method Service list:
list() {
return this.http.get<Programming[]>(this.API)
.pipe(
tap(console.log)
)
}
}
Component:
export class ProgrammingListComponent implements OnInit {
schedules: Programming[];
schedules$:Observable<Programming>
constructor(private service: ProgrammingService) {}
ngOnInit() {
this.schedules$ = this.service.list();
}
}
model:
export interface Programming {
_id: number;
date:Date;
dayOfWeek:string;
times: [];
}
Dear Isa, the problem begins at
ngfor
, so it can be the model way as it can be just an error in ngfor, there is no way to know. If you want to displaytimes:
Ngfor may make some sense, but it has to show something related to the error. Ngfor is a feature of Angular and not of Typescript, so it is much more proof that the error is in it, or from it, but to know we need to show an example Minimum, Complete and Verifiable, read mainly the part that says "Ensure that the example actually reproduces the problem!".– Guilherme Nascimento