<input [(ngModel)]="username">{{ username | checkStatus }}
import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'checkStatus', pure: false }) export class PipeTestComponent implements PipeTransform { transform(value: string): string { if (value == '0') { return '審覈中'; } if (value == '1') { return '審覈經過'; } if (value == '-1') { return '審覈退回'; } } }
記得將該component註冊到ngModule中,不然不會生效,若是想在某個組件中使用這個pipe,直接在html上寫就能夠了html