2021-05-11 19:09:25 +02:00
|
|
|
import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
|
2021-04-06 09:32:52 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-network-status',
|
|
|
|
templateUrl: './network-status.component.html',
|
|
|
|
styleUrls: ['./network-status.component.scss'],
|
2021-05-11 19:09:25 +02:00
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush,
|
2021-04-06 09:32:52 +02:00
|
|
|
})
|
|
|
|
export class NetworkStatusComponent implements OnInit {
|
|
|
|
noInternetConnection: boolean = !navigator.onLine;
|
|
|
|
|
2021-05-11 19:09:25 +02:00
|
|
|
constructor(private cdr: ChangeDetectorRef) {
|
2021-04-06 09:32:52 +02:00
|
|
|
this.handleNetworkChange();
|
|
|
|
}
|
|
|
|
|
2021-05-11 19:09:25 +02:00
|
|
|
ngOnInit(): void {}
|
2021-04-06 09:32:52 +02:00
|
|
|
|
|
|
|
handleNetworkChange(): void {
|
|
|
|
setTimeout(() => {
|
|
|
|
if (!navigator.onLine !== this.noInternetConnection) {
|
|
|
|
this.noInternetConnection = !navigator.onLine;
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}
|
|
|
|
this.handleNetworkChange();
|
|
|
|
}, 5000);
|
|
|
|
}
|
|
|
|
}
|