在浏览器中找不到ionic 4.2.1网络信息

时间:2018-10-18 22:15:50

标签: cordova ionic-framework ionic3 apache-cordova

我正在遵循该插件的官方文档,但无法使该插件正常工作。

app.module.ts

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

home.ts

export class HomePage {
  level:any
  conn:any
  constructor(
    public navCtrl: NavController,
    private network:Network,
    public battery:BatteryStatus
  ) {}

  subscribeConnections(){
    let connectSubscription = this.network.onConnect().subscribe(() => {
      console.log('network connected!');
      this.conn = this.network.type;
      setTimeout(() => {
        if (this.network.type === 'wifi') {
          console.log('we got a wifi connection, woohoo!');
        }
      }, 3000);
    });

    const subscription = this.battery.onChange().subscribe(status => {
      console.log(status.level, status.isPlugged);
      this.level = status.level;
   });
  }

  ionViewDidLoad(){
    console.log('end');
    this.subscribeConnections();
  }

}

home.html

<ion-header>
  <ion-navbar>
    <ion-title>
      Ionic Blank
    </ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
  The world is your oyster.
  <p>
    If you get lost, the <a href="http://ionicframework.com/docs/v2">docs</a> will be your guide.
  </p>
  <p>level: {{level}}</p>
  <p>type: {{conn}}</p>
</ion-content>

batteryStatus和Network在模拟器中运行时是正常的,这是正常的,因为它需要cordova才能工作,但是networkinformation我在浏览器中找不到任何结果,错误在哪里?

我执行以下代码

未找到:

ionic cordova run browser

未找到:

ionic serve -l

发现:

ionic cordova run android -l

0 个答案:

没有答案