angular2 pipe 用法

前端之家收集整理的这篇文章主要介绍了angular2 pipe 用法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. <input [(ngModel)]="username">{{ username | checkStatus }}
  1. import { Pipe,PipeTransform } from '@angular/core';
  2.  
  3. @Pipe({
  4. name: 'checkStatus',pure: false
  5. })
  6.  
  7. export class PipeTestComponent implements PipeTransform {
  8.  
  9. transform(value: string): string {
  10. if (value == '0') {
  11. return '审核中';
  12. }
  13. if (value == '1') {
  14. return '审核通过';
  15. }
  16. if (value == '-1') {
  17. return '审核退回';
  18. }
  19. }
  20.  
  21. }

记得将该component注册到ngModule中,否则不会生效,如果想在某个组件中使用这个pipe,直接在html上写就可以了

猜你在找的Angularjs相关文章