Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable, EventEmitter } from '@angular/core';
- /*
- * Include service and subscrube to isOnlineEmitter
- */
- @Injectable({
- providedIn: 'root'
- })
- export class NetConnectionCheckService {
- private readonly timer: number = 5000;
- private isOnline: boolean = true;
- public isOnlineEmitter: EventEmitter<boolean> = new EventEmitter()
- constructor() {
- this.setTimer();
- }
- private setTimer(): void {
- setInterval(_ => {
- if(this.isOnline !== navigator.onLine) {
- this.isOnline = navigator.onLine;
- this.isOnlineEmitter.emit(navigator.onLine);
- }
- }, this.timer)
- }
- }
Add Comment
Please, Sign In to add comment