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>My birthday{{birth | date | uppercase}}</div> <div>My birthday{{birth | date : ' yyyy-MM-dd ' }}</div> <div>My Birthday{{numberA | number : ' 2.1-4 ' }}</div> <div>My Birthday{{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() { } by OnInit () { this.birth = new Date(); this.numberA = 3.1514926; } }