Problems with ngFor object containing objects

Asked

Viewed 413 times

2

I’m using it as follows:

<ion-item *ngFor="let via of lines.daysOperations?.week?.tripA?.routes; let i = index" text-wrap (click)="toggleGroup(i+'i')"
                      [ngClass]="{active: isGroupShown(i+'i')}">

And you’re making this mistake:

Error: Uncaught (in Promise): Error: Cannot find a differ supporting Object '[Object Object]' of type 'Via Green Corner'. Ngfor only Supports Binding to Iterables such as Arrays. Error: Cannot find a differ supporting Object '[Object Object]' of type 'Via Green Corner'. Ngfor only Supports Binding to Iterables such as Arrays.

My object is like this:

{ outros itens ..., routes: {name: "lorem inpsum", schedules:{10:00, 11:00, 12:00}}}

How can I fix this ??

I put the operator elvis ? but did not solve my problem.

  • The object is var Lines = { daysOperations: { week: { tripa: {Routes: { }} }}} ?

  • yes in this stream

  • Are your "Routes" an array? If so, is it the only array? ngFor only serves to iterate on arrays

  • I don’t understand your question.

  • Inside Routes I have: Routes: { name: "Lorem Inpsum" Schedules:{ 11:00, 12:00 } }

  • @Gabrielberlanda my Routes is an object, and inside it I have an array.

  • You should use ngFor in an array, on whom do you want to iterate? in Schedules? If yes you should change the end of your ngFor => *ngFor="Let via of Lines.daysOperations?. week?. tripa? .routes.Schedules"

  • 1

    ngFor expects an array to iterate, it will not iterate on an object...

  • My other question was whether all the levels you access are objects and only the last level is an array, because you have some objects with the name in plural, e.g., Lines and daysOperations

  • @Gabrielberlanda Actually today this Routes he is one, but the idea is several Routes... However I identified an error in the data model. I will check further, anything update the question.. Thank you for so far to all

  • Yes, in my view you have some levels there, and you should go iterating one by one until you reach the last

  • lines.daysOperations?.week?.tripA?.routes is being accessed as an object, so returned '[object Object]', it is necessary to check whether this parameter routes is really an array to be iterated by ngFor

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.