首页 文章

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

提问于
浏览
2

我试图将ngFor项作为参数传递给管道,但得到一个错误:

例外:调用节点模块失败,错误:错误:模板解析错误:TypeError:无法读取未定义的属性'toUpperCase'(“{} ng-container [错误 - >] * ngFor =”让评级等级| groupFilter:{}“

这是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 回答

  • 2

    {{name}} 删除 {{}}

    {{}} never(event)="..." [prop]="..."*someDirective="..." 一起使用

相关问题