Angular2 - 将ngFor项作为参数传递给管道?

时间:2017-02-23 14:10:04

标签: angular parameters pipe ngfor

我试图将ngFor项作为参数传递给管道但是出错:

  

异常:调用节点模块失败,错误:错误:模板   解析错误:TypeError:无法读取属性'toUpperCase'   undefined(“{{name}} ng-container [ERROR - >] * ngFor =”让评级为   评级| groupFilter:{{name}}“

这是html:

            <tr *ngFor="let name of measureNames">
            <td>{{name}}</td>
            <td><input class="form-control"></td>
            <ng-container *ngFor="let rating of ratings | groupFilter:{{name}} ">
                <ng-container *ngFor="let key of rating | keys">
                    <td *ngIf="key=='measureRating'"><input class="form-control" value={{rating[key]}}></td>
                </ng-container>
            </ng-container>
        </tr>

这是我的烟斗:

    import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'groupFilter',
    pure: false
})

export class GroupFilterPipe implements PipeTransform {
    transform(items: any[], args: string): any {
        console.log("Filter ARGS: " + args);
        return items.filter(item => item.measureName==args);
    }
}

1 个答案:

答案 0 :(得分:2)

{{}}

中删除{{name}}

{{}} 从不(event)="..." [prop]="..."*someDirective="..."

一起使用