typescript - Aurelia - value converter using promise -


i need format date using format returned promise. tried returning promise toview(value). 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, 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;             });         } } 

as far know, cannot use async functionality within value converters. 1 solution see, pass format parameter viewmodel value converter (through view). means need fetch format within viewmodel, kind of destroys whole point of value converters...

another solution see, adjust formatservice caches format (assuming 'format' doesn't change often). way, getformat function synchronous , can use within value converter. of course, need find way initialize format within formatservice before value converters called.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -