javascript - Angular 2 中的过滤器 ngFor 循环

标签 javascript angular

我有这门课:

    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/

相关文章:

javascript - 如何确定我的页面是在普通浏览器还是 SAP CL_GUI_HTML_VIEWER 中呈现

javascript - JS中如何实现数字乘法

javascript - 使用 Javascript 保护电子邮件 - 代码如何工作?

angular - angular cli中的接口(interface)类型格式是什么?

angular - *ngFor 对象 angular2

javascript - 限制段落之间的选择

angular - 异常 : Root segment cannot have matrix parameters

angular - 'npm 错误!缺少脚本 : ngcc' error with NPM

javascript - 保持 HTML5 背景视频全屏(在移动设备上)

javascript - 检查 2 个框之间的一系列复选框