Search code examples
angulartemplatesngfor

How can I break from an *ngFor loop in Angular 4?


How can I break from an *ngFor loop in Angular 4?

I just want this loop to break after it executes once.

  <div *ngFor="let thing of things">
    <div *ngIf="thing == otherThing">
      <h4>Sub Title</h4>
      ***BREAK HERE***
    </div>
  </div>

Solution

  • You can't break *ngFor.

    But you can build a custom pipe to filter the data.

    But as Jus10's said, the better way is to do it in ts-file.