【问题标题】:Angular 2: Condition in *ngForAngular 2:*ngFor 中的条件
【发布时间】:2016-01-24 19:47:07
【问题描述】:

我希望在 HTML 中构建一个元素列表,但在该列表中的某个属性上。

<ul>
    <li *ngFor="#record of recordsService.records">
        {{record.recordTitle}} -
        <strong>{{record.recordArtist}}</strong>
    </li>
</ul>

在#record 对象中,有一个 isSingle 属性,该属性为真或假。

我想跳过循环中的错误元素,而不必在 DOM 中留下空的 DIV

【问题讨论】:

  • 只需过滤组件类中的元素。在视图中不需要这样做。

标签: javascript angularjs angular


【解决方案1】:

您可以在数组recordsService.records 上应用Pipe 以仅过滤您想要的值。

Pipe 类似于 angular1 中的filterhttps://angular.io/docs/ts/latest/guide/pipes.html

【讨论】:

猜你喜欢
  • 2017-05-07
  • 1970-01-01
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
  • 1970-01-01
  • 2018-03-31
  • 2019-01-28
  • 2018-06-13
相关资源
最近更新 更多