ionic3中创建pipe管道

1、使用ionic cli创建pipe管道文件

ionic g pipe parse-date

该命令会在src文件夹创建pipes/parse-date/parse-date.ts文件,并且会在pipes文件夹创建pipes.module.ts文件

2、修改parse-date.ts文件(红色部分为生成文件基础上修改的内容)

import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'parseDate',
})
export class ParseDatePipe implements PipeTransform {

  transform(value: string, ...args) {
    return value.substr(0,value.lastIndexOf(":"));
  }
}

3、在app.module.ts文件注册管道

import {PipesModule} from '../pipes/pipes.module';

......

imports: [
......,
PipesModule
]

4、在html页面中使用管道

{{expense.begintime | parseDate}}
原文地址:https://www.cnblogs.com/modou/p/9594403.html