Watch AllMovie
Watch AllMovie

Reputation: 33

How to use ngFor for 4 elements?

Now I use :

<app ngxSlickItem *ngFor="let item of items" [item]="item"></app>

to bring out all elements. But I need to bring out 4div elements. Like this:

<div>
<app ngxSlickItem *ngFor="let item of items" [item]="item"></app>
<app ngxSlickItem *ngFor="let item of items" [item]="item"></app>
<app ngxSlickItem *ngFor="let item of items" [item]="item"></app>
<app ngxSlickItem *ngFor="let item of items" [item]="item"></app>
</div>

How could I do that with ngFor? I have a slider, and I need to show 4 elements at start.

Upvotes: 2

Views: 1089

Answers (1)

Stefan Svrkota
Stefan Svrkota

Reputation: 50633

Use SlicePipe:

<app ngxSlickItem *ngFor="let item of items | slice:0:4" [item]="item"></app>

First argument is start, second argument is end.

Read more about SlicePipe here.

Upvotes: 6

Related Questions