Angular 6 customPipe startDate endDate

时间:2019-02-22 16:59:44

标签: angular

我是新的前端,我想在两个日期之间创建自定义数据管道 我的烟斗:

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

0 个答案:

没有答案