【问题标题】:Using Slice Pipe with variable parameters in *ngFor在 *ngFor 中使用带有可变参数的切片管道
【发布时间】:2017-12-10 04:55:15
【问题描述】:

使用 Angular2 管道 slice 我可以这样做,只显示我的 items 的前五个元素。

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

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

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

【问题讨论】:

  • 使用不带双引号&lt;ion-item *ngFor='let item of items | slice:start:end'&gt;
  • 谢谢。我不小心在我的 *.ts 文件中添加了“start:0”和“end:5”,而不是“start = 0”和“end = 5”。然后它显然不起作用......当我纠正它时,它没有引号就可以正常工作 - 正如你所说。谢谢!

标签: angular ionic-framework ionic2


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2017-02-02
    • 2019-05-15
    • 1970-01-01
    • 2017-10-05
    • 2017-09-09
    • 1970-01-01
    • 2018-02-03
    • 1970-01-01
    • 2021-11-18
    相关资源
    最近更新 更多