gpt4 book ai didi

javascript - 如何为 ngFor 循环添加条件

转载 作者:行者123 更新时间:2023-12-05 09:32:01 24 4
gpt4 key购买 nike

我正在使用 Clarity 创建表格。他们有自己的语法,clrDgItems , 但结构与 ngFor 相同。

我想为我的表格创建一个循环,它过滤前 10 个项目,然后是第二个表格,它只显示项目 11-20。

您还应该能够转到下一页。也就是说,第一个表更新到项目 21-30,第二个表更新到 31-40

我的第一个想法是,

ngFor="let employee of employees; i as index; i < firstMaxIndex;"
ngFor="let employee of employees; i as index; i > firstMaxIndex && i < secondMaxIndex"

但是 ngFor 循环不是那样工作的,我收到错误:NG5002: Parser Error: Unexpected token <

最佳答案

使用切片

{{ value_expression | slice : start [ : end ] }}

像这样:

ngFor="let employee of employees | slice : 0 : firstMaxIndex"

ngFor="let employee of employees | slice : firstMaxIndex : secondMaxIndex"

关于javascript - 如何为 ngFor 循环添加条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68450803/

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