【问题标题】:Angular2 - passing ngFor item into a pipe as a parameter?Angular2 - 将ngFor项目作为参数传递到管道中?
【发布时间】:2017-02-23 14:10:03
【问题描述】:

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

异常:调用节点模块失败并出现错误:错误:模板 解析错误:TypeError:无法读取属性“toUpperCase” undefined ("{{name}} ng-container [ERROR ->]*ngFor="let rating of 收视率 | 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);
    }
}

【问题讨论】:

  • 试试*ngFor="let rating of ratings | groupFilter:name"。在name 附近没有{{ }}

标签: angular parameters pipe ngfor


【解决方案1】:

{{name}}中删除{{}}

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-19
  • 1970-01-01
  • 2022-09-27
  • 2017-12-18
  • 1970-01-01
相关资源
最近更新 更多