在 *ngFor 中使用带有可变参数的切片管道 [英] Using Slice Pipe with variable parameters in *ngFor

查看:10
本文介绍了在 *ngFor 中使用带有可变参数的切片管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Angular2 管道 slice 我可以做这样的事情来只显示我的 items 的前五个元素.

Using the Angular2 pipe slice I can do something like this to only show the first five elements of my items.

<ion-item *ngFor='let item of items | slice:0:5">

如何使用变量而不是硬编码 0 和 5?我想做这样的事情并在我的 *.ts 文件中定义 startend.

How can I use variables instead of hardcoding 0 and 5? I want to do something like this and define start and end in my *.ts file.

<ion-item *ngFor='let item of items | slice:"start":"end"'>

推荐答案

只需从 startend 中删除 "(双引号)变量

Just remove "(double quotes) from the start and end variable

<ion-item *ngFor='let item of items | slice:start:end'>

这篇关于在 *ngFor 中使用带有可变参数的切片管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆