admin管理员组文章数量:1310392
In my angular 4 application I need to use ngFor with less than conditon. I mean I do not want to show all the item of sampleArray
, instead I want to display only first 10 items, just like in normal java script we have i < sampleArray.length
or i < 10
, etc these kind of conditions I want to use in ngFor, is it possible?
<li *ngFor="let a of sampleArray">
<p>{{a.firstname}}</p>
<p>{{a.lastname}}</p>
</li>
In my angular 4 application I need to use ngFor with less than conditon. I mean I do not want to show all the item of sampleArray
, instead I want to display only first 10 items, just like in normal java script we have i < sampleArray.length
or i < 10
, etc these kind of conditions I want to use in ngFor, is it possible?
<li *ngFor="let a of sampleArray">
<p>{{a.firstname}}</p>
<p>{{a.lastname}}</p>
</li>
Share
Improve this question
asked Jun 30, 2017 at 11:50
Madasu KMadasu K
1,8632 gold badges39 silver badges76 bronze badges
2
- there already an answer for the same check this link stackoverflow./questions/37818677/… – Rahul Singh Commented Jun 30, 2017 at 11:57
- 1 Possible duplicate of How can I limit ngFor repeat to 10 items in Angular 2? – developer033 Commented Jun 30, 2017 at 12:47
2 Answers
Reset to default 6You need to simply use slice.
<li *ngFor="let a of sampleArray | slice:0:9">
<p>{{a.firstname}}</p>
<p>{{a.lastname}}</p>
</li>
<li *ngFor="let a of sampleArray; let i=index">
<div *ngIf="i<2">
<p>{{a.firstname}}</p>
<p>{{a.lastname}}</p>
</div>
</li>
Updated:
<ng-container *ngFor="let a of sampleArray; let i=index">
<li *ngIf="i<11">
<p>{{a.firstname}}</p>
<p>{{a.lastname}}</p>
</li>
</ng-container>
本文标签: javascriptangular ngFor with conditionStack Overflow
版权声明:本文标题:javascript - angular ngFor with condition - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741800953a2398219.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论