angular - angular2 ngfor only if index is less than certain number -


i'm using ngfor display varying amount of items. want limit amount of items can display 5 use:

<li  *ngfor="let item of items; let = index;">      <div *ngif="i < 4">        //more stuff ...      </div> </li> 

but it seems rendering space items on index = 4.

if try:

<li  *ngfor="let item of items; let = index;" *ngif="i < 4"> //notice ngif 

nothing displayed.

any ideas?

you can way:

<li *ngfor="let item of items | slice:0:5; let = index;">   <div>     //more stuff ...    </div> </li> 

maybe that's option works you.


Comments