Break NgFor Loop in Angular 2

There is no option to break ngFor. You can use a custom pipe that doesn't return values after the element where the condition is met.

For more concrete approaches please provide more concrete information about what you actually try to accomplish.


I had to break the loop so i followed the following approach.

I don't know whether it's helpful or not still sharing that piece of code.

As Gunter mentioned:

There is no option to break ngFor.

It's just an alternate way to do so.

<ng-container *ngFor="let product of products; let i = index">
    <div *ngIf="i < 10">
        <span> product.name </span>
    </div>
</ng-container>

Tags:

Angular