0

I have this ngIf:

<div class="clearfix" *ngFor="let item of result.items;let i = index">
   <h5 *ngIf="itHasOpt(item)">
      <span class="numberCircle">{{ i+1 }}</span>
   </h5>
...

the i is affected by the parent div with *ngFor for walk through the items.

My question is, how can I stop the increment of the i in some conditions? for example to tell the attached function if something is true to keep the i count as is?

Or just another idea how to control the increment of the i?

4
  • i is the index and so you can't halt the loop control.
    – Mike Tung
    Nov 13, 2018 at 15:39
  • I noticed that.. So is there another option I can handle the iteration?
    – Roi Sadika
    Nov 13, 2018 at 15:40
  • without user interaction not really...
    – Mike Tung
    Nov 13, 2018 at 15:41
  • One solution would be to filter the list in code: this.filteredList = this.result.items.filter(x => this.itHasOpt(x));, and use that filtered list in the template.
    – ConnorsFan
    Nov 13, 2018 at 15:51

1 Answer 1

0

You can't change incrementation it's by default. Although you can call function from controller and modify display value if you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.