I need to format Date using format returned by promise. I tried returning promise from toView(value). But that doesn't work.
@autoinject
export class DateTimeValueConverter {
constructor(private formatService:FormatService) {
}
toView(value) {
return this.formatService.getFormat().then(format=>
moment(value).format(format)
);
}
}
Here's FormatService's code, which works properly
export class FormatService {
private format;
constructor(private http:AppHttp) {
this.format= null;
}
public getFormat() : Promise<string>{
if (this.format){
var promise = new Promise<string>((resolve, reject)=>{
resolve(this.format);
});
return promise;
}
return this.http.get('format')
.then((format) => {
if (format){
this.format= format;
}
return format;
});
}
}