Angular2-将ngFor项目作为参数传递到管道中? [英] Angular2 - passing ngFor item into a pipe as a parameter?

查看:344
本文介绍了Angular2-将ngFor项目作为参数传递到管道中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

异常:调用节点模块失败,并显示错误:错误:模板 解析错误:TypeError:无法读取的属性'toUpperCase' 未定义("{{name}} ng容器[ERROR->] * ngFor =让等级为 评分| groupFilter:{{name}}"

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}} "

这是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);
    }
}

推荐答案

{{name}}

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

这篇关于Angular2-将ngFor项目作为参数传递到管道中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆