简体   繁体   English

角度2:* ngFor中的条件

[英]Angular 2: Condition in *ngFor

I am looking to build a list of elements within HTML, but on a certain property within that list. 我希望在HTML中构建一个元素列表,但是在该列表中的某个属性上。

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

Within the #record object, there is an isSingle property which is either true or false. 在#record对象中,有一个isSingle属性,它是true或false。

I would like to skip over false elements in the loop, without having to leave empty DIVs in the DOM 我想跳过循环中的错误元素,而不必在DOM中留下空DIV

You can apply a Pipe on your array recordsService.records to filter only value you want. 您可以在数组recordsService.records上应用Pipe以仅过滤所需的值。

Pipe is similar to filter in angular1: https://angular.io/docs/ts/latest/guide/pipes.html Pipe类似于angular1中的filterhttps ://angular.io/docs/ts/latest/guide/pipes.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM