1

I can not get the battery data, the level of charge and whether it is connected or not, what am I doing wrong? Thank you in advance.

I'm placing "BatteryStatus" in app.module.ts in providers. The code of the home is only for printing on the console while there is a change in the battery. I am using the example of the Ionic 4 documentation but still I have the following error: ERROR TypeError: Invalid event target.

I HAVE FOLLOWED THE SENTENCES OF THE DOCUMENTATION

The code of the home is the following:

import { Component } from '@angular/core';
import { BatteryStatus } from '@ionic-native/battery-status/ngx';
@Component({
    selector: 'app-home',
    templateUrl: 'home.page.html',
    styleUrls: ['home.page.scss'],
})
export class HomePage  {
    subscription: any;
    constructor(private batteryStatus: BatteryStatus) {
      this.checkStatus()
    }
    checkStatus(){
      this.subscription = this.batteryStatus.onChange().subscribe(status => {
        console.log(status.level, status.isPlugged);
     });
    }
    stop(){
      // stop watch
      this.subscription.unsubscribe();
    }
}

I hope that the status value of the battery is printed in the console, but I get the following error: Error

  • Possible duplicate of [Angular 2 - subscribing to Observable.fromEvent error: "Invalid event target"](https://stackoverflow.com/questions/42454740/angular-2-subscribing-to-observable-fromevent-error-invalid-event-target) – Phonolog May 21 '19 at 07:13

0 Answers0