I've tried using Ionics native plugin "Network" but it fails because of a supposedly missing provider. In order to avoid any mistakes I've installed a fresh installation of Ionic and the required dependencies:
ionic cordova plugin add cordova-plugin-network-information
npm install @ionic-native/network
Then I've added the dependency to home's constructor:
import { Component } from '@angular/core';
import { Network } from '@ionic-native/network/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(private network: Network) {
// to nothing ...
}
}
... and will get the following error message after executing ionic serve
:
ERROR Error: Uncaught (in promise):
Error: StaticInjectorError(AppModule)[HomePage -> Network]:
StaticInjectorError(Platform: core)[HomePage -> Network]:
NullInjectorError: No provider for Network!
Error: StaticInjectorError(AppModule)[HomePage -> Network]:
StaticInjectorError(Platform: core)[HomePage -> Network]:
NullInjectorError: No provider for Network!
System information
Ionic:
ionic (Ionic CLI) : 4.12.0 (/Users/samnowakowski/node_modules/ionic)
Ionic Framework : @ionic/angular 4.4.0
@angular-devkit/build-angular : 0.13.9
@angular-devkit/schematics : 7.3.9
@angular/cli : 7.3.9
@ionic/angular-toolkit : 1.5.1
Cordova:
cordova (Cordova CLI) : 9.0.0 ([email protected])
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (1 plugins total)
System:
Android SDK Tools : 26.1.1 (/Users/admin/Library/Android/sdk)
NodeJS : v10.15.3 (/usr/local/bin/node)
npm : 6.9.0
OS : macOS Mojave
Xcode : Xcode 10.2.1 Build version 10E1001
Open app module (app.module.ts) and below code :
import { Network } from '@ionic-native/network/ngx';
@NgModule(
...
providers: [
Network
]
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With