Ionic nested lists index(numbering) problem

Hi all, I have nested ngFor with indexes(See code below).

<div *ngFor="let category of categoriesWithFoodies; let catIndex = index">
    <span>{{catIndex}}</span>
    <ul class="foodies-list">
		<li *ngFor="let foodie of category.foodies; let foodIndex = index">
		    <span>{{foodIndex}}</span>
		</li>
	</ul>
</div>

Now food indexes are like this:

cat 1
  food 1
  food 2
  food 3
cat 2
  food 1
  food 2
cat 3
  food 1
  food 2

And i need them to be like this:

cat 1
  food 1
  food 2
  food 3
cat 2
  food 4
  food 5
cat 3
  food 6
  food 7

Do you know how to achive this?

Hey @sergi95,

Would you mind to post your categoriesWithFoodies here please?

I think you don’t understand my question well, otherwise you would not ask me to show categoriesWithFoodies object.

Ok, you know better your problem. Please let me know when you fix it. i may learn something from.

@rapropos any ideas?

Angular doesn’t think like this, so you are going to have to manually seed these numbers you want into the various foodie objects.

Hi. Not precisely the Angular way, but if you’re not using the food counter for anything else than display, you can try using CSS named counters:

Just skip resetting the food counter every time there’s a new list.
Best regards.

No css can’t help me here :slight_smile:

You should be more courteous to a person who is trying to help you. BTW, if you had listened and showed the categoriesWithFoodies data structure, then everyone would have been able to see that you are trying to illogically represent the foodies arrays.

Nevertheless, if your use case is hell-bent on requiring this, you can simply do that through interpolation. Hint: You’ve access to the categories.foodies array length and you can use any valid expressions inside the interpolation braces.

1 Like

I think what i write is enough to understand my object structure. This forum looks useless and that makes me angry.

You don’t have to post here.

We would be very happy to not answer you question if you don’t want us to.
Just let me know and I can also close this discussion here.

2 Likes

Instead of help. cool :+1:

Do you understand that you are trying to represent the underlying data in an illogical manner?? Whether that is possible or not is a different matter and I’ve given you hints already for that.

Now this was kind of expected behaviour from you I guess, IMHO, you should look around a bit and realise that this is a community driven platform and everyone is trying their best to help each other without any selfish gains. What does your conscience say, shouldn’t we be a bit more respectful to each other? Not that you’ve said anything wrong to me personally, but you should respect the place where you’ve come to get some help and people are actually trying to do just that.

2 Likes

why did you decide that “I think you don’t understand my question well, otherwise you would not ask me to show categoriesWithFoodies object.” i said with bad tone? he was trying to help i understand and thanks to him, but i didn’t had much time and wanted a quick answer from a man who knew exactly what i wanted and he didn’t look like that man, that’s why i told him that, but then you appear and begin an intrigue and lets not speak too much about this. I want ionic to be good i like it and want its forum to be good too. When ionman needs help we must help

Unfortunately, it came across as negative tone only. Nevertheless, after you’ve put forward your point, I’d rather err on the side of a “misunderstanding”. So, everything is good!

Following suit now.

That’s more like it man, thanks for the positivity :v:

1 Like