【发布时间】:2018-09-21 00:02:24
【问题描述】:
我想通过仅显示具有特定 groupId 的 items 来过滤我的角度表的 dataSource > 属性。
component.html
<mat-table [dataSource]="groupSource | filter : currentGroupId"></mat-table>
filter.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'filter'
})
// return items of a group
export class FilterPipe implements PipeTransform {
transform(group: any[], currentGroupId: number): any[] {
return group.filter( item=> item.groupId = currentGroupId);
}
}
但是,我收到此错误:
错误类型错误:group.filter 不是函数
在 FilterPipe.push../src/app/filter.pipe.ts.FilterPipe.transform (filter.pipe.ts:9)
在 checkAndUpdatePureExpressionInline (core.js:9949)
在 checkAndUpdateNodeInline (core.js:10518)
在 checkAndUpdateNode (core.js:10476)
在 debugCheckAndUpdateNode (core.js:11109)
在 debugCheckDirectivesFn (core.js:11069)
在 Object.eval [as updateDirectives] (BasketComponent.html:144)
在 Object.debugUpdateDirectives [as updateDirectives] (core.js:11061)
在 checkAndUpdateView (core.js:10458)
在 callViewAction (core.js:10699)
我做错了什么?
【问题讨论】: