首页 > 解决方案 > 异步的角度自定义管道

问题描述

我正在使用角度(7+)并具有以下自定义管道:

@Pipe({
  name: 'enumtostring'
})
export class EnumtostringPipe implements PipeTransform {

  constructor(private translateEnumService: TranslateenumService) { }

  transform(value: any, type$?: any): any {
    if(value && type$) {
        // this returns an observable of type Observable<string>
        return this.translateEnumService.translateEnumObservable(type$, value);
    }
    return value;    
  }

}

要使用这个管道,我也必须使用关键字async

{{ KalkulationsTyp.Monat | enumtostring : KalkulationsTyp | async }}

如何重写我的管道,以便在使用时可以省略异步管道?从异步管道继承?我怎么做?

标签: angular

解决方案


推荐阅读