angular - Check internet connection when app starts in ionic -


i using ionic 3, problem app checks connection after has changed only. need check connection when main page loads trigger change in ui. here have gotten fa:

constructor(public navctrl: navcontroller,private changedetect:           applicationref, private weatherprovider: weatherprovider, private formbuilder: formbuilder, private network: network, public alertctrl:   alertcontroller, private platform: platform) {  let disconnectsubscription = this.network.ondisconnect().subscribe(()    => {   console.log('network disconnected :-(');   this.netstatus = false;   this.loginbtntxt ="ofline";   settimeout(() => {     // if (this.network.type === 'wifi') {     //   console.log('we got wifi connection, woohoo!');     // }   }, 3000); });  // watch network connection let connectsubscription = this.network.onconnect().subscribe(() => { console.log('network connected!'); this.netstatus = true; this.loginbtntxt ="online"; // got connection need wait briefly // before determine connection type. might need wait. // prior doing api requests well. settimeout(() => { if (this.network.type === 'wifi') {   console.log('we got wifi connection, woohoo!');  }  }, 3000);  });  this.login = this.formbuilder.group({ email: ['', validators.required], password: [''], }); } 

in case lost in this, found answer:

navigator.online 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -