File

src/app/modules/shared/services/connection-service/connection.service.ts

Index

Properties
Methods

Constructor

constructor(router: Router, utilService: UtilService)
Parameters :
Name Type Optional
router Router No
utilService UtilService No

Methods

monitor
monitor()
Returns : Observable<boolean>

Properties

Private connectionMonitor
Type : Observable<boolean>
Public router
Type : Router
Public utilService
Type : UtilService
import { Injectable } from '@angular/core';
import { UtilService } from '../../services/util/util.service';
import { Observable } from 'rxjs';
import { Router } from '@angular/router';

@Injectable({
  providedIn: 'root'
})
export class ConnectionService {

  private connectionMonitor: Observable<boolean>;

  constructor(public router: Router, public utilService: UtilService) {
    this.connectionMonitor = new Observable((observer) => {
      observer.next(navigator.onLine);
      window.addEventListener('offline', (e) => {
        observer.next(false);
      });
      window.addEventListener('online', (e) => {
        observer.next(true);
      });
    });
  }

  monitor(): Observable<boolean> {
    return this.connectionMonitor;
  }
}

results matching ""

    No results matching ""