0

I have an error Object is not a function, when I start the ionic app. Maybe someone knows why I've got an error Object is not a function and where is the mistake? Thanks for all. This is a service provider for checking connectivity user when using an ionic app. I've tried to

network.ts

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

@Injectable()
export class NetworkService {

  info: any = {
    connected: true,
    type: "none"
  };

  disconnectSubscription: any;
  connectSubscription: any;

  private infoConnection = new Subject<any>();
  infoConnection$ = this.infoConnection.asObservable();

  constructor(
    private network: Network,
    private platform: Platform
  ) {
    this.disconnectSubscription = this.network.onDisconnect().subscribe(() => {
      this.sendStatus();
    });

    this.connectSubscription = this.network.onConnect().subscribe(() => {
      this.sendStatus();
    });
  }

  sendStatus() {
    if (this.platform.is("cordova")) {
      setTimeout(() => {
        this.info = {
          connected: this.isConnected(),
          type: this.getConnectionType()
        }
        this.infoConnection.next(this.info);
      }, 3000);
    }
  }

  isConnected() {
    if (this.platform.is("cordova")) {
      let hasConnection = this.network.type == "none" || this.network.type == 'unknown' ? false : true;
      return hasConnection;
    } else {
      return true;
    }
  }

  getConnectionType() {
    if (this.platform.is("cordova")) {
      return this.network.type;
    } else {
      return true
    }
  }
}

app.module.ts

import { PeopleServiceProvider } from '../providers/people-service/people-service';
import { Network } from '@ionic-native/network/ngx';
import { NetworkService } from '../providers/network/network';
@NgModule({
  declarations: [
    MyApp,
    HomePage,
    LoginPage,
    IzvjestajPage,
    NalogPage,
    OtkazPage,
    ServicesPage,
    RegistrationPage
  ],
  imports: [
    BrowserModule,
    HttpClientModule,
    IonicModule.forRoot(MyApp),

  ],

  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    LoginPage


  ],
  providers: [
    StatusBar,
    HttpClientModule,
    Geolocation,
    NativeGeocoder,
    GoogleMaps,
    StatusBar,
    LocationAccuracy,
    NetworkService,

    {provide: ErrorHandler, useClass: IonicErrorHandler},
    PeopleServiceProvider,
    Network

  ]
})
export class AppModule {}

app.component.ts

import { Component } from '@angular/core';
import { Platform, ModalController, Events } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { Network } from '@ionic-native/network/ngx';
import { ToastController } from 'ionic-angular';
import { NetworkService } from '../providers/network/network';

@Component({
  templateUrl: 'app.html'
})

export class MyApp {
  rootPage: any = LoginPage;

  infoConnection$ = this.networkService.infoConnection$;

  constructor(platform: Platform, statusBar: StatusBar, modalCtrl: ModalController, private network: Network, private toast: ToastController, private networkService: NetworkService) {
    platform.ready().then(() => {

      this.networkService.infoConnection$.subscribe(infoConnection => {
        console.log(infoConnection)
      })

    })

}

  }
  • Can you please copy and paste the error with line numbers from the console? – Vinod Bhavnani Mar 01 '19 at 11:57
  • @VinodBhavnani https://imgur.com/9bguCkO here is an error –  Mar 01 '19 at 12:00
  • Sorry I am on my work network. Can't open that URL :) Can you please copy and paste it? – Vinod Bhavnani Mar 01 '19 at 12:00
  • @VinodBhavnani : ERROR TypeError: Object(...) is not a function at Network.onDisconnect (index.js:61) at new NetworkService (network.ts:24) at _createClass (core.js:10935) at _createProviderInstance$1 (core.js:10907) at resolveNgModuleDep (core.js:10892) at NgModuleRef_.get (core.js:12129) –  Mar 01 '19 at 12:02
  • @VinodBhavnani (index.js:61) (network.ts:24) (core.js:10935) (core.js:10907)...etc –  Mar 01 '19 at 12:05
  • I see that someone else also has the same problem here. No fix is provided. https://github.com/ionic-team/ionic-native/issues/2937 – Vinod Bhavnani Mar 01 '19 at 12:16
  • __WEBPACK_IMPORTED_MODULE_2__ionic_native_network_ngx__.a.onDisconnect is not a function at new NetworkService (network.ts:23) –  Mar 01 '19 at 12:17
  • use ionic native v4 for ionic 3 https://ionicframework.com/docs/v3/native/ – Suraj Rao Mar 02 '19 at 12:24
  • Possible duplicate of [Getting "Uncaught (in promise): TypeError: Object(...) is not a function" Error from Ionic-native VideoEditor Plugin](https://stackoverflow.com/questions/54467262/getting-uncaught-in-promise-typeerror-object-is-not-a-function-error) – Suraj Rao Mar 02 '19 at 12:25

0 Answers0