Guest User

Untitled

a guest
Jan 20th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import { Injectable, EventEmitter } from '@angular/core';
  2.  
  3. /*
  4. * Include service and subscrube to isOnlineEmitter
  5. */
  6.  
  7. @Injectable({
  8. providedIn: 'root'
  9. })
  10. export class NetConnectionCheckService {
  11. private readonly timer: number = 5000;
  12. private isOnline: boolean = true;
  13. public isOnlineEmitter: EventEmitter<boolean> = new EventEmitter()
  14.  
  15. constructor() {
  16. this.setTimer();
  17. }
  18.  
  19. private setTimer(): void {
  20. setInterval(_ => {
  21. if(this.isOnline !== navigator.onLine) {
  22. this.isOnline = navigator.onLine;
  23. this.isOnlineEmitter.emit(navigator.onLine);
  24. }
  25. }, this.timer)
  26. }
  27. }
Add Comment
Please, Sign In to add comment