0

Sample hierarchy of my ionic 2 app..

few services which implements my baseService class to inject header and all that in each http requests.

Now I have a NativeStorage.get of user's info in constructor of the baseService in which I get user data already and update my local variable in that class only to be sent in HTTP requests.

But problem is each time I hit a new service it reinitialize my baseService again and so my user data gets empty and by the time NativeStorage.get starts its work http req is already gone with empty requests

base service

export class CommonRestProvider {}

a sample service

export class PlaceListService extends CommonRestProvider{ }

base service dependecies setting in app.module.ts

providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}, ConstantsService, CommonRestProvider]
Luckyy
  • 1,021
  • 4
  • 15
  • 29
  • Needed this http://stackoverflow.com/questions/40899313/return-resolved-observable-from-inside-of-a-promise – Luckyy Mar 04 '17 at 17:39

1 Answers1

0

If you want to set header for every http request, you can check my other answer.

And, if you still want to use your current solution, you can useObservable or Promise for your user data, and for every requests, you need to use subscribe or then to send request in them.

Mavlarn
  • 3,807
  • 2
  • 37
  • 57