cic-staff-client/src/app/shared/network-status/network-status.component.ts

28 lines
782 B
TypeScript
Raw Normal View History

2021-05-11 19:09:25 +02:00
import { Component, OnInit, ChangeDetectionStrategy, ChangeDetectorRef } from '@angular/core';
@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,
})
export class NetworkStatusComponent implements OnInit {
noInternetConnection: boolean = !navigator.onLine;
2021-05-11 19:09:25 +02:00
constructor(private cdr: ChangeDetectorRef) {
this.handleNetworkChange();
}
2021-05-11 19:09:25 +02:00
ngOnInit(): void {}
handleNetworkChange(): void {
setTimeout(() => {
if (!navigator.onLine !== this.noInternetConnection) {
this.noInternetConnection = !navigator.onLine;
this.cdr.detectChanges();
}
this.handleNetworkChange();
}, 5000);
}
}