- <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上写就可以了