Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic native中的网络状态,ionic2错误_Ionic2 - Fatal编程技术网

Ionic native中的网络状态,ionic2错误

Ionic native中的网络状态,ionic2错误,ionic2,Ionic2,我试图在ionic2中使用网络api,Ionic native docs示例不起作用: 我的代码是: import { Network } from 'ionic-native'; networkType:string; constructor() { // watch network for a connection let connectSubscription = Network.onConnect().subscribe(() => { this.ne

我试图在ionic2中使用网络api,Ionic native docs示例不起作用: 我的代码是:

import { Network } from 'ionic-native';

networkType:string;
constructor() {
    // watch network for a connection
    let connectSubscription = Network.onConnect().subscribe(() => {
      this.networkType = Network.type;
    });    
  }
我收到错误
类型“typeof Network”上不存在属性“type”。
如果有人在ionic2中成功使用了Ionic native,请提供帮助

我已经做了爱奥尼亚插件添加cordova插件网络信息

this.networkType = Network.connection; 
通过查看network.d.ts的源代码,我发现:

 * @advanced
 * The `connection` property will return one of the following connection types: `unknown`, `ethernet`, `wifi`, `2g`, `3g`, `4g`, `cellular`, `none`
 */
export declare class Network {
    /**
     * Return the network connection type
     */
    static connection: string;
    /**
     * Get notified when the device goes offline
     * @returns {Observable<any>} Returns an observable.
     */
    static onDisconnect(): Observable<any>;
    /**
     * Get notified when the device goes online
     * @returns {Observable<any>} Returns an observable.
     */
    static onConnect(): Observable<any>;
}
*@高级
*“connection”属性将返回以下连接类型之一:`unknown`、`ethernet`、`wifi`、`2g`、`3g`、`4g`、`cellular`、`none``
*/
导出声明类网络{
/**
*返回网络连接类型
*/
静态连接:字符串;
/**
*当设备脱机时收到通知
*@returns{Observable}返回一个可观察的。
*/
静态onDisconnect():可观察到;
/**
*设备联机时收到通知
*@returns{Observable}返回一个可观察的。
*/
静态onConnect():可观察到;
}
应该是

this.networkType = Network.connection; 
通过查看network.d.ts的源代码,我发现:

 * @advanced
 * The `connection` property will return one of the following connection types: `unknown`, `ethernet`, `wifi`, `2g`, `3g`, `4g`, `cellular`, `none`
 */
export declare class Network {
    /**
     * Return the network connection type
     */
    static connection: string;
    /**
     * Get notified when the device goes offline
     * @returns {Observable<any>} Returns an observable.
     */
    static onDisconnect(): Observable<any>;
    /**
     * Get notified when the device goes online
     * @returns {Observable<any>} Returns an observable.
     */
    static onConnect(): Observable<any>;
}
*@高级
*“connection”属性将返回以下连接类型之一:`unknown`、`ethernet`、`wifi`、`2g`、`3g`、`4g`、`cellular`、`none``
*/
导出声明类网络{
/**
*返回网络连接类型
*/
静态连接:字符串;
/**
*当设备脱机时收到通知
*@returns{Observable}返回一个可观察的。
*/
静态onDisconnect():可观察到;
/**
*设备联机时收到通知
*@returns{Observable}返回一个可观察的。
*/
静态onConnect():可观察到;
}

仅onConnect()一项,我就遇到了同样的问题,这个解决方案帮助我让它正常工作

将您的ionic native更新到最新版本,然后它就可以正常工作了


运行
npm-rm--save-ionic-native
,然后
npm-install--save-ionic-native@latest

仅onConnect()一项就存在同样的问题,此解决方案帮助我使其正常工作

将您的ionic native更新到最新版本,然后它就可以正常工作了


运行
npm-rm--save-ionic-native
,然后
npm-install--save-ionic-native@latest

在更新到最新版本的Ionic Native(2.2.16)之前,我一直使用此功能。我的网络插件是1.3.1版。话虽如此,我在获取fire的onConnect订阅时遇到了问题。在更新到最新版本的Ionic Native(2.2.16)之前,我一直都有这个问题。我的网络插件是1.3.1版。话虽如此,我在获取fire的onConnect订阅时遇到了麻烦。