【问题标题】:Is there a built-in pipe to show only part of entries in an array是否有内置管道仅显示数组中的部分条目
【发布时间】:2017-03-31 17:47:07
【问题描述】:

我正在展示产品:

<li *ngFor="let product of products">{{product.id}}</li>

我想限制使用组件上的属性显示的条目数。是否有内置管道可以做到这一点,或者我应该创建自己的管道?

这是我的看法:

<li *ngFor="let product of products | length[propertyOnComponent]">{{product.id}}</li>

因此,如果propertyOnComponent 为 3,则只会显示 3 个条目。

【问题讨论】:

    标签: angular angular2-pipe


    【解决方案1】:

    slicehttps://angular.io/docs/ts/latest/guide/pipes.html

    <li *ngFor="let product of products | slice:0:propertyOnComponent">{{product.id}}</li>
    

    【讨论】:

      【解决方案2】:

      实现这一点的最佳方法是将slice pipestartend 参数一起使用。

      <li *ngFor="let product of products | slice:0:propertyOnComponent">
        {{product.id}}
      </li>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-31
        • 1970-01-01
        相关资源
        最近更新 更多