gpt4 book ai didi

Angular 2 - ngFor 显示数组中的最后 3 个项目

转载 作者:太空狗 更新时间:2023-10-29 19:36:20 26 4
gpt4 key购买 nike

得到一个包含许多项目的数组,我想显示最后 3 个项目。

进入我的html

          <li *ngFor="let project of projects;">
<h2>{{ project.name }}</h2>
<p>{{ project.meta_desciption }}</p>
</li>

现在显示所有项目(超过 20 个)。我怎样才能只显示最后 3 个?我想我需要在我的代码中使用“last”,但无法弄清楚 https://angular.io/docs/ts/latest/api/common/index/NgFor-directive.html

最佳答案

<li *ngFor="let project of (projects | slice:projects.length - 4);">

您可能需要一些额外的 null 检查 projects 或确保它始终是一个数组。

关于Angular 2 - ngFor 显示数组中的最后 3 个项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38975981/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com