我使用纯管道来过滤数据,我知道不推荐这样做,但在我的情况下,过滤只会在url更改时发生,大多数情况下是在页面加载时。这是烟斗
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;
}
}
发布于 2018-09-03 06:49:05
好吧,出于某种原因,typescript不让我在数组中推值。以下是对有类似问题的人的答案
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;
}
}
}
https://stackoverflow.com/questions/52140664
复制相似问题