Ionic check internet connection every seconds?

Ionic check internet connection enabled or not in every 2 seconds. when open my app

Bad idea, IMHO. Deal with it when you are needing a network connection, and not at an arbitrary interval.

my idea is wrong fine. but when i submit my data that time i will off my network. that time give a alert for network is off. that is my question.

I don’t understand what you are writing, but I see no benefit in bothering the user about network status at any time other than when a network request fails.

I usually use this

this.network.onChange().subscribe(() => {
  switch (this.network.type) {
    case '2g':
      console.log('probably not very fast ...');
      break;
    case 'wifi':
      console.log('wohoo wifi ...');
      break;
  }
});

my question is check my internet status every 2 seconds

I am trying my best to be polite, but my answer is that I think you should not be doing that.

Ok thanks. thanks for your clarifications

And if you need always a connection? It’s a bad idea do a subscribe?

i got my issues in my code.

You can check this thread too

hello sir,
how i can check no internet access when wifi/mobile data connected in ionic 3.
my code is:
//---- check internet -----

	this.alert = this.alertCtrl.create({
		title: 'Disconnected',
		message: 'Please connect your device to internet',
		buttons: [
		{
			text: 'Close',
			handler: () => {
			   this.platform.exitApp();
			}
		}
		],  enableBackdropDismiss: false 
	});	  
  	
	this.network.onDisconnect().subscribe(res=>{
	  this.online=false;
	  this.Status='Disconnected';
	  console.log('network was Disconnected');
      this.alert.present();			
	});

	this.network.onConnect().subscribe(res=>{				

		if(this.network.type == "unknown" || this.network.type == "none" || this.network.type == undefined){
			alert("The device is not online"+this.network.type);
			//console.log("The device is not online");
			this.online = false;
			this.Status='Disconnected';
			this.alert.present();	
		}else{
			alert("The device is online"+this.network.type);
			this.online = true;
			this.Status='Connected';
			this.alert.dismiss();
		}
  			
		//define again alert
		this.alert = this.alertCtrl.create({
		title: 'Disconnected',
		message: 'Please connect your device to internet',
		buttons: [
		{
			text: 'Close',
			handler: () => {
			   this.platform.exitApp();
			}
		}
		],  enableBackdropDismiss: false 
		});
	});

this.task = setInterval(() => {
this.checkInternet(); //function there you can do your code for Network inplementation
}, 3000);