Battery status for ionic 2 using typescript

Hi All,

I am currently applying the battery status in ionic… But I always get errors…
image

What’s the best tutorial that I can use, that will really work.
Hoping for your positive response.
Thank you.

The docs, which explicitly tell you to declare every plugin as a provider in your app module.

@rapropos Thanks for the reply…
I have already imported BatteryStatus in my app.module.ts but still got the same error.

@NgModule({
  ...
  
  providers: [
    ...
    BatteryStatus
    ...
  ]
  ...
})

Hello.
Am I going to insert that one here?

Yes, like this

providers: [
    {provide: ErrorHandler, useClass: IonicErrorHandler}, BatteryStatus
  ]

It works… thanks for that @MattE :blush::wink::joy:

Great!

2 things:

  • Mark this post as solved
  • Change the category from ionic to ionic 2
    Just for future reference for your fellow developers

Okay @MattE … but I my problem now is getting the battery status.

I used this tutorial…
image
but it says that :::
image
… I really don’t know about this because I’m new to this ionic thing.
What will I do now??

If you’re using the code from the docs (which you can find over here), and doing everything as stated over there, you could always try and change the type of status from StatusObject to any. Simply because of what you’re compiler is telling you (that it doesn’t know the type statusobject).

Thanksss @luukschoen , I already declared the StatusObject but still get the same error.
image

I’m not sure, but I guess you have to import StatusObject at the top, next to the import of BatteryStatus

Yes. If you want to use StatusObject as a type, you should import it, probably at the top of the page.

Thank you very much @MattE:blush: and @luukschoen:blush:

You’re really a big help.
Now, I can continue doing my app.