2017-01-15 2 views
1

Ich versuche Netzwerk api in ionic2, Ionic-native docs Beispiel zu verwenden, funktioniert nicht: Mein Code ist:Netzwerkstatus in Ionic-native, ionic2 Fehler

import { Network } from 'ionic-native'; 

networkType:string; 
constructor() { 
    // watch network for a connection 
    let connectSubscription = Network.onConnect().subscribe(() => { 
     this.networkType = Network.type; 
    });  
    } 

Ich bin Fehler immer Property 'type' does not exist on type 'typeof Network'. Wenn eine man hat erfolgreich Ionic-native in ionic2 verwendet, bitte helfen.

Ich habe ionic plugin add cordova-plugin-network-information getan

+0

ich das hatte, bis ich auf die neueste Version von Ionic-Native (2.2.16) aktualisiert funktionieren. Mein Netzwerk-Plugin ist Version 1.3.1. Nachdem ich das gesagt habe, habe ich Probleme, das onConnect-Abonnement in Brand zu setzen. – Astravagrant

Antwort

0

sein sollte

this.networkType = Network.connection; 

auf den Quellcode von network.d.ts Mit Blick fand ich diese:

* @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>; 
} 
0

ich das gleiche Problem hatte für onConnect() allein und diese Lösung half mir, es funktioniert,

Aktualisieren Sie Ihre Ionen ic-native auf die neueste Version, und es sollte dann

Run npm rm --save ionic native und dann npm install --save [email protected]