gpt4 book ai didi

angular - ionic 网络类型 = 空

转载 作者:搜寻专家 更新时间:2023-10-30 21:23:42 25 4
gpt4 key购买 nike

我正在 Ionic 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);
});

}
}

关于angular - ionic 网络类型 = 空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44329198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com