我有纯粹的管道来过滤数据我知道它不推荐但在我的情况下过滤器只会在网页更改大多数情况下在页面加载时发生。这是管子
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'sortPipe'
})
export class SortPipePipe implements PipeTransform {
listArr = []
transform(value: any[], args?: string): any[] {
value.forEach((val, index) => {
if (val.group.indexOf(args) > -1) {
console.log(val); // this retuning object and not array
listArr.push(val); // not allowed
}
});
retune val ; //this is object not array
});
return null;
}
}
好吧,因为某些原因得到它打字稿并没有让我在数组中推高价值。以下是有类似问题的人的答案
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'listFilter'
})
export class ListFilterPipe implements PipeTransform {
list = [];
transform(value: any[], args?: string): any[] {
this.list = [];
if ( typeof value !== 'undefined' ) {
value.forEach(val => {
if (val.group.indexOf(args) > -1) {
this.list.push(val);
}
});
return this.list;
}
}
}