iam dev One App在离子V2 TS中。我的network.type等于null。有什么问题?
import { Network } from '@ionic-native/network';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [ProviderAccessApi]
})
export class HomePage {
user : string;
pass:string;
constructor(public navCtrl: NavController, public providerAPI:ProviderAccessApi, private platform: Platform, public alertCtrl : AlertController, public network : Network) {
console.log('HomePage carragada com sucesso')
alert(network.type);
}
首先,请注意,您应该将与网络相关的代码放置在this.platform.ready().then(() => {...});
的内部,以在平台准备就绪时执行它。
import { Network } from '@ionic-native/network';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [ProviderAccessApi]
})
export class HomePage {
user : string;
pass:string;
constructor(public navCtrl: NavController,
public providerAPI: ProviderAccessApi,
private platform: Platform,
public alertCtrl : AlertController,
public network : Network) {
console.log('HomePage carragada com sucesso');
this.platform.ready().then(() => {
// Now all cordova plugins are ready!
alert(network.type);
});
}
}