本文介绍了Ionic的Network本机插件缺少的提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我尝试使用Ionics本机插件网络,但是由于据说缺少提供程序而失败。为了避免发生任何错误,我已经安装了Ionic的全新安装以及所需的依赖项:

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

然后我已经

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 ...
  }
}

...,并且在执行 ionic serve后将得到以下错误消息

... 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!

系统信息

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


推荐答案

打开应用模块(app.modul e.ts)及以下代码:

Open app module (app.module.ts) and below code :

import { Network } from '@ionic-native/network/ngx';

@NgModule(
   ...
   providers: [
      Network
   ]
);

这篇关于Ionic的Network本机插件缺少的提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:53