我试图在 angular 6 中设置管道,使用服务将文本转换为其他(返回可观察的方法)
我尝试了以下代码,但我需要返回一个字符串而不是 Promise
管道:
import { Pipe, PipeTransform } from '@angular/core';
import { TimeZoneService, TimeZone } from '../services/Global/timezone.service';
//import { resolve } from 'dns';
import { reject } from 'q';
import { Observable } from 'rxjs';
@Pipe({
name: 'utcToText'
})
export class UtcToTextPipe implements PipeTransform {
private timezoneLst: TimeZone[] = [];
constructor(private _timezoneSvc : TimeZoneService) {}
async transform(timezone: any, args?: any){
this.timezoneLst = await this._timezoneSvc.getTimeZonesLst().toPromise();
return this.timezoneLst.find(x => x.utc.indexOf(timezone) > -1).text;
}
}
Run Code Online (Sandbox Code Playgroud)
html:
<span>{{subscription.time_zone | utcToText}</span> …Run Code Online (Sandbox Code Playgroud)