I have encountered an issue while trying to use Ionics native plugin "Network" as it fails due to a missing provider. To prevent any errors, I performed a fresh installation of Ionic along with the necessary dependencies:
ionic cordova plugin add cordova-plugin-network-information
npm install @ionic-native/network
After that, I included the dependency in the constructor of the home component:
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) {
// do nothing ...
}
}
However, upon running ionic serve
, I encountered the following error message:
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!
Here is some 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 (<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="52313d20363d24337f3e3b30126b7c627c63">[email protected]</a>)
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