我是新的前端,我想在两个日期之间创建自定义数据管道 我的烟斗:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'customRangeFilter'
})
export class CustomRangeFilterPipe implements PipeTransform {
transform(items, from?:Date, to?:Date) {
if(items && items.lenght){
let startDate = new Date(from);
let endDate = new Date(to);
let a = items.filter(
m => new Date(m.date) >= startDate && new Date(m.date) <= endDate
)
return a;
}else{
return items;
}
}
}
在component.html
中
我的其他烟斗 从“ @ angular / core”导入{Pipe,PipeTransform}; @管({ 名称:“ customRangeFilter” }) 导出类CustomRangeFilterPipe实现PipeTransform {
transform(items, from?:Date, to?:Date,) {
if(items && items.lenght){
let startDate = new Date(from);
let endDate = new Date(to);
let a = items.filter(
m => new Date(m.date) >= startDate && new Date(m.date) <= endDate
)
return a;
}else{
return items;
}
}
在侧面模型中看不到进行日期比较的customPipe