internet connection status in angular code example
Example: angular no internet detection
import { Observable, Observer, fromEvent, merge } from 'rxjs';
import { map } from 'rxjs/operators';
ngOnInit(){
this.createOnline$().subscribe(isOnline => console.log(isOnline));
}
createOnline$() {
return merge<boolean>(
fromEvent(window, 'offline').pipe(map(() => false)),
fromEvent(window, 'online').pipe(map(() => true)),
new Observable((sub: Observer<boolean>) => {
sub.next(navigator.onLine);
sub.complete();
}));
}