Accessing Platform outside of the App


#1

I’m trying to retrieve some Platform information in a service, and it does not appear that we can just inject the Platform into a service but only the App, or maybe I’m wrong?

So instead I’ve decided to publish an event when the platform is ready, and I will listen to this event in my service, however it seems that when my service is instantiated, the event has already been published and therefore I never receive it. So 2 questions:

  1. Is there any way to get the Platform outside of the @App ?
  2. If not, am I forced to create a service that references the Platform or can I subscribe to an event after it has been published?

#2

Hi,

Same here, i can’t inject Platform, Platform is not “@Injectable()”.

I need to acces platform.is(‘android’) in a service, this service is

  • @Injectable
  • with the following constructor:

constructor(private localDataBase: LocalDataBase,
private platform: Platform,
private dataServer: DataServer) {

I have added in the app.ts:
providers: [Platform]

But I m stuck, i have the following error:
uncaught Cannot resolve all parameters for ‘Platform’(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that ‘Platform’ is decorated with Injectable.

Platform is not injectable.

Someone know how to use Platform in an injectable service?


#3

This is the cause of your problem. Don’t do that.


#4

Thanks for your answer.

If i don’t do that: app.ts:providers: [Platform]

I have another error:

reflective_provider.js:232
Uncaught Cannot resolve all parameters for ‘User’(LocalDataBase, Platform, undefined). Make sure that all the parameters are decorated with Inject or have valid type annotations and that ‘User’ is decorated with Injectable.

User is my injectable Service.


#5

That “undefined” looks like a problem with the DataServer parameter.


#6

Dam! I’m tired, I missed it

Thanks a lot.