Azure App Service with Ionic 2 and shared providers

I’ve successfully created providers that can talk to Azure App Service. However, I am struggling with a working approach to create a working provider that can be used across my application. The underlying Mobile Apps JS SDK has an object named WindowsAzure.MobileServicesClient. It’s important to create this object once in your application versus every time you make an API call as it keeps track of the user’s authentication. Therefore, Provider1 and Provider2 have to both use the same object.

For example, I create some provider called AzureService and my other providers import this. I register the providers in my App.Module.ts file so that they can be accessed anywhere. However, when I do that and I later go to use the WindowsAzure object, it is not defined. This is not the typical WindowsAzure is not defined error because I didn’t declare it in the module. It’s actually failing because the provider is running before platform.ready() fires. That has to occur otherwise, you’ll get errors like these.

So here is the part where I am not sure how to proceed. How do I use my provider across the pages in my application but ensure that platform.ready() fires first? I’m sure if I had more experience with Angular 2 and Ionic 2, the answer might be obvious but I am confused on this one.

I think the key here is when precisely you mean by “the provider is running”. If the answer is “the provider’s constructor gets called”, then what I would do is wrap whatever you are doing in there that is being problematic in its own platform.ready().then block.

Thanks. I knew I was overthinking this. I was thinking about somehow loading the provider after platform.ready() as opposed to having my code inside of the provider only execute after platform.ready().