angular2 pipe 用法

<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

相关文章
相关标签/搜索