0

I have been trying to create a function that is similar to http.get(...) but not doing any http. Basically what I have done is that I defined a function

async myFunc(): Observable<string> {
 var myObservable: Observable<string>;

  //.....
  // the rest of the function's code comes here
  // ...

 return myObservable;
}

But I always get an error that it is not compatible with ES5/ES3 and should return a Promise object? But I am wondering how it became possible with Angular 5's http.get function? Where clearly it returns an Observable.



Thanks,
Artanis

1 Answer 1

1

The async/await functionality works with promises. You can use Observable.defer to define an Observable with async/await functionality.

See this post for more information: https://medium.com/@benlesh/rxjs-observable-interop-with-promises-and-async-await-bebb05306875

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your answer. I will try this one and will update you after.
I was trying your suggestion, but I was wondering how do I access the fields of the enclosing objects? Thanks.
Consider asking a new question and elaborating with some example code as to what "enclosing objects" you are referring to so we can better help.
thanks for your patience. Yes, I have created a new question. I have posted it here: stackoverflow.com/questions/51690433/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.