Ionic 2 function return problem

Yes, you’re performing an async operation and then outside of the async you’re trying to get the results immediately, that won’t work. I suggest you move your this.http.get into a service, map your result, return that and then subscribe to it.

Also, don’t use var but get used to use let instead. The block scoping solves a lot of issues that exist with var. Don’t make use of any unless absolutely necessary. It makes your code easier to debug. In this post you can see an example about how you should handle subscribables inside your class.

1 Like