Angular2 - passing ngFor item into a pipe as a par

2019-02-26 02:08发布

问题:

Im trying to pass an ngFor item into a pipe as a paramter but get an error:

Exception: Call to Node module failed with error: Error: Template parse errors: TypeError: Cannot read property 'toUpperCase' of undefined ("{{name}} ng-container [ERROR ->]*ngFor="let rating of ratings | groupFilter:{{name}} "

This is the 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>

and this is my pipe:

    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:

remove {{}} from {{name}}

{{}} never goes together with (event)="..." [prop]="..." or *someDirective="..."