我有这门课:
export class Tache {
id: number;
text: string;
stat: number;
}
Stat 可以等于 0、1 或 2。
当 stat = 0 时,我会打印taches,我尝试使用过滤器来制作它
<md-list *ngFor="let tache of taches | filter : 'tache.stat' : '0'" (click)="onSelect(tache)" [class.selectionnee]="tache === tacheSelectionnee">
但我收到此错误:
zone.js:569 Unhandled Promise rejection: Template parse errors:
The pipe 'filter' could not be found ("
最佳答案
你不需要过滤器。通过用模板包装来分解逻辑。对 Angular 4 使用 ng-template。
<template *ngFor="let tache of taches">
<md-list *ngIf="tache.stat==0"
(click)="onSelect(tache)"
[class.selectionnee]="tache === tacheSelectionnee">
</md-list>
</template>
关于javascript - Angular 2 中的过滤器 ngFor 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43443510/