Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a built-in pipe to show only part of entries in an array

I'm showing products:

<li *ngFor="let product of products">{{product.id}}</li>

I want to limit the number of entries shown using the property on component. Is there a built-in pipe to do that or I should create my own pipe?

Here is how I see it:

<li *ngFor="let product of products | length[propertyOnComponent]">{{product.id}}</li>

So, if propertyOnComponent is 3, then only 3 entries will be shown.

like image 291
Max Koretskyi Avatar asked Dec 05 '25 19:12

Max Koretskyi


1 Answers

See slice in https://angular.io/docs/ts/latest/guide/pipes.html

<li *ngFor="let product of products | slice:0:propertyOnComponent">{{product.id}}</li>
like image 146
Günter Zöchbauer Avatar answered Dec 08 '25 11:12

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!