How to bind the value of a promise in au2

hello.greet is an async function.

  1. If I call hello.greet like so:
    this.answerFromIC = hello.greet(;
    I get
    [object Promise]

  2. If I call hello.greet like so:
    this.answerFromIC = await hello.greet(;
    I get
    Unexpected reserved word ‘await’

  3. If I call hello.greet like so :
    this.answerFromIC = hello.greet( (function (answer) { return answer;});

                 I still get                    [object Promise]

What is the correct way of calling this so that I get the actual value of the hello.,greet?

Hi @mparikh, it is bit difficult to answer without seeing the code contextually. But I think you are missing the async keyword. It should be something like this:

async yourMethod() {
  this.answerFromIC = await hello.greet(;

If you are binding this promise to your HTML view and want to show the settled value in the UI you might be looking for this: promise.bind - The Aurelia Docs.

Having said that it depends how you are using this. I would suggest to post more code so that the context is clearer.

1 Like