执行过滤器时发生此错误:
ERROR TypeError: filter.trim is not a function
过滤器本身可以工作,只是想摆脱这种错误。
applyFilter() {
let searchFilter: any = {
filterValue: this.search,
};
this.dataSource.filter = searchFilter;
this.load()
}
html:
<div fxFlex="50">
<mat-form-field class="full-width">
<input matInput [(ngModel)]="search" placeholder="Filter" (keyup.enter)="applyFilter()">
<button mat-mini-fab matSuffix color="primary" class="btn" (click)="applyFilter()" matTooltip="Filter">
<mat-icon>search</mat-icon>
</button>
</div>
答案 0 :(得分:1)
根据Mat table documentation过滤器应为字符串值,并且您正在传递和对象。因此,applyFilter应为
applyFilter() {
this.dataSource.filter =this.search ? this.search.trim().toLowerCase() : '';
}