import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'multi' }) export class MultiPipe implements PipeTransform { transform(value: any, args?: any): any { if (args == null) { args = 1; } return value * args; } }
<div>我的生日{{birth | date | uppercase}}</div> <div>我的生日{{birth | date :'yyyy-MM-dd'}}</div> <div>我的生日{{numberA | number :'2.1-4'}}</div> <div>我的生日{{numberA | multi :2}}</div>
import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-bind', templateUrl: './bind.component.html', styleUrls: ['./bind.component.css'] }) export class BindComponent implements OnInit { private birth: Date; private numberA: number; constructor() { } ngOnInit() { this.birth = new Date(); this.numberA = 3.1514926; } }