How can I limit *ngFor repeat to some number of items in Angular?

You can use the Slice Pipe for limit ngFor.

{{ value_expression | slice : start [ : end ] }}

<li *ngFor="let item of items | slice:0:5; let i=index>{{item.name}}</li>

You can also try this approach

<ng-container *ngFor="let item of items" let-i="index">
  <li *ngIf="i<5">{{item.name}}</li>
</ng-container>

Leave a Reply

Your email address will not be published. Required fields are marked *