Ionic 3-网络信息插件-Object(...)不是函数(...) [英] Ionic 3 - network-information plugin - Object(...) is not a function(…)
问题描述
我需要在ionic 3 angular 4项目中实现网络信息插件.我已经使用
I need to implement network information plugin in an ionic 3 angular 4 project. I have installed a network plugin using
$ ionic cordova plugin add cordova-plugin-network-information
$ npm install --save @ionic-native/network@5.0.0
安装后,我在 app.component.ts 中使用了此插件,但由于
After installation, I have used this plugin in app.component.ts but I'm getting an error as
错误错误:未被捕获(承诺):TypeError:对象(...)在设备或仿真器上都不是函数(...).
我正在共享我在此应用中使用的本机核心版本和插件版本.
I'm sharing native-core and plugin versions that I have used in this app.
"@ionic-native/core": "5.0.0"
"@ionic-native/network": "5.0.0"
"cordova-plugin-network-information": "2.0.1"
请注意:
我尝试升级"@ionic-native/core" to "5.2.0"
和"@ionic-native/network" to "5.2.0"
.但是问题没有解决.
Please Note:
I have tried upgrading "@ionic-native/core" to "5.2.0"
and "@ionic-native/network" to "5.2.0"
. But the issue was not resolved.
在这里,我无法降级npm或"@ionic-native/core" to "4.2.0"
插件,因为我在此应用中使用了许多插件,它们在@ 5.0.0版本上运行良好.
Here, I cannot degrade plugin npm version or "@ionic-native/core" to "4.2.0"
as I have many plugins used in this app which are working fine @ version "5.0.0".
下面是我的 app.component.ts
Below is my app.component.ts
import { Network } from '@ionic-native/network/ngx';
...
constructor(private network: Network) {
this.platform.ready().then(() => {
// watch network for a disconnection
let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
console.log('network disconnected!');
});
})
}
下面是我的 package.json
Below is my package.json
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
...
"@ionic-native/core": "^5.0.0",
"@ionic-native/network": "^5.0.0",
...
"cordova-android": "7.1.4",
"cordova-plugin-device": "2.0.2",
"cordova-plugin-network-information": "2.0.1",
"ionic-angular": "^3.9.2",
}
以下是我的 开发系统 信息
Below is my development system information
Ionic:
ionic (Ionic CLI) : 4.3.1 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.2
@ionic/app-scripts : 3.2.1
Cordova:
cordova (Cordova CLI) : 8.1.2 (cordova-lib@8.1.1)
Cordova Platforms : android 7.1.4
Cordova Plugins : no whitelisted plugins
System:
Android SDK Tools : 26.1.1 (/Users/###/Library/Android/sdk)
ios-deploy : 1.9.4
NodeJS : v8.11.3 (/usr/local/bin/node)
npm : 6.4.1
OS : macOS High Sierra
Xcode : Xcode 10.1 Build version 10B61
有人遇到过这个问题吗?请帮助我,因为如果没有网络插件,我将无法前进.谢谢您的宝贵时间.
Has anyone encountered this issue? Please help me as I'm not able to move forward without the network plugin. Thanks for your time.
推荐答案
The problem is that you are using the /ngx
import which is for Ionic version 4. If you go read the changelog you will see that version 5 and up Requires Angular 7.1 and TypeScript 3.1
.
尝试将插件降级至4.20.0:
Try to downgrade plugin to 4.20.0 like this :
npm uninstall @ionic-native/network
然后
npm install @ionic-native/network@4.20.0
然后像这样删除导入中的ngx:
import { Network } from '@ionic-native/network';
And remove ngx in import like this :
import { Network } from '@ionic-native/network';
这篇关于Ionic 3-网络信息插件-Object(...)不是函数(...)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!