Well-defined value is undefined in calling context

I have an angular component that calls a service. The component has a method like this:

    this.member = this.service.getSomeValue(id);
    console.log("component: member: " + this.member);
    //member is undefined

And the service:

         .then(result => {this.something = result});
    console.log("service: this.something:" + this.something);
    // this.something is {"foo":"bar","1":"3"}
    return this.something;

Why is the value undefined in the component, but perfectly well defined in the service?

Read more here: https://stackoverflow.com/questions/64900557/well-defined-value-is-undefined-in-calling-context

Content Attribution

This content was originally published by Dan at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: