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

标签 javascript html angular clarity

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

相关文章:

javascript - Axios:获取两个请求 OPTIONS & POST

javascript - ajax 中的 jQuery 表单提交(带文件)

javascript - AngularJS:在同一元素上包含多个指令

javascript - 如何根据使用 Angular2 发出的 post 请求的响应呈现输出

angular - serviceWorker 删除 Origin 请求 header

javascript - 在 Javascript 中预加载图像

html - 如何使 css 运动路径响应?

javascript - 从 SVG 代码附加 SVG 元素

angular - 使用标签在 Protractor 中只执行一个特征文件

javascript - React 中作为 prop 传递时区分 img 和 svg