我正在使用 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/