Using Async and Await in Ionic


Hi to every one, we never used await/async, so the question could be also a stupid one but what do we wrong?

This is our code:

  constructor() {
       let text = this.textAsync();
       console.log('text: ', text);
  async textAsync() {
    let val = await this._text(); 
    return val;
  _text(): Promise<any> {
    return new Promise((resolve, reject) => {

The log is never text: TEEEEXXTTTTT but something like that
text: ZoneAwarePromise {__zone_symbol__state: null, __zone_symbol__value: Array[0]}

I’m sure there is a simple solution :smile:



Does someone have an idea???


You console.log the promise, not the result.
Maybe that will work better:

constructor() {
       let text = this.textAsync().then( text =>
         console.log('text: ', text)


And proves you don’t need await async to work with async stuff, as imho proper use of promises and observables is much cleaner