I need to call in each of the pages, the connection status of the wifi. Then use a provider, but in the MyApp(app.component.ts) constructor, call the provider(ConectivityServiceProvider) only once.
app.component.ts
import { ConectivityServiceProvider } from '...'
import { Network } from '.....';
export class MyApp {
conectivity:boolean
constructor(private provider: ConectivityServiceProvider,public network: Network){
platform.ready().then(() => {
this.conectivity=provider.isOnline();
// call once in all pages
if(this.conectivity){
//do someting
}else //do something
}
}
}
Provider:
@Injectable()
export class ConectivityServiceProvider {
statusConectivity: boolean =true;
constructor(public network: Network){
this.network.onDisconnect().subscribe(() => {
this.statusConectivity=false;
});
}
isOnline(){
return this.statusConectivity;
}
}
If I put everything inside the provider in the MyApp class, it does call in each of the pages and not just once. Why using the provider only calls once?