Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@ionic-native/[email protected] subscribe to onChange resulting error #3649

Closed
revion opened this issue Apr 9, 2021 · 0 comments · Fixed by #3651
Closed

@ionic-native/[email protected] subscribe to onChange resulting error #3649

revion opened this issue Apr 9, 2021 · 0 comments · Fixed by #3651

Comments

@revion
Copy link

revion commented Apr 9, 2021

I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://forum.ionicframework.com/ or https://ionicworldwide.herokuapp.com/

Current behavior:
@ionic-native/[email protected] always produces error whenever subscribing to onChange function like this

ReferenceError: mapTo is not defined
at vendor.js:91511
at Network.push.kwrG.Network.onChange (vendor.js:91513)
at AppComponent. (main.js:126)
at Generator.next ()
at fulfilled (vendor.js:93513)
at ZoneDelegate.invoke (polyfills.js:3010)
at Object.onInvoke (vendor.js:82972)
at ZoneDelegate.invoke (polyfills.js:3009)
at Zone.run (polyfills.js:2769)
at polyfills.js:3503

Expected behavior:
Successfully subscribing to onChange Observerable.

Steps to reproduce:
Implement the code like in the Related code: from a new Ionic project.

Related code:

import { Component } from '@angular/core';
import { Network } from '@ionic-native/network/ngx';
import { Platform } from '@ionic/angular';
import { Subscription } from 'rxjs';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['app.component.scss'],
})
export class AppComponent {

  onChange: Subscription;

  constructor(
    private platform: Platform,
    private network: Network,
  ) {
    this.initiateApp();
  }

  async initiateApp()
  {
    try
    {
      await this.platform.ready();
      this.onChange = this.network.onChange()
      .subscribe(
        (status) => this.successChange(status),
        (error) => this.failedChange(error)
      );

      console.log("my subs onchange", this.onChange);
    }
    catch (error)
    {
      console.log("Platform never ready", error);
    }
  }

  successChange(output:"connected" | "disconnected")
  {
    console.log("success network onChange", output);
  }

  failedChange(error:any)
  {
    console.log("failed network onChange", error);
  }
}

Other information:
None.

Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):

Ionic:

   Ionic CLI                     : 6.13.1 (C:\Users\User\AppData\Roaming\npm\node_modules\@ionic\cli)
   Ionic Framework               : @ionic/angular 5.6.3
   @angular-devkit/build-angular : 0.1102.8
   @angular-devkit/schematics    : 11.2.8
   @angular/cli                  : 11.2.8
   @ionic/angular-toolkit        : 3.1.1

Capacitor:

   Capacitor CLI   : 2.4.7
   @capacitor/core : 2.4.7

Utility:

   cordova-res                          : not installed
   native-run (update available: 1.3.0) : 0.2.9

System:

   NodeJS : v12.21.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.14.8
   OS     : Windows 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant