Usage

Angular

Usage examples for Angular.

import { Component, OnInit, OnDestroy } from '@angular/core';
import { checkConnectivity, watchConnectivity } from 'netlytics';

@Component({
  selector: 'app-root',
  template: '<div>{{ online ? "Online" : "Offline" }}</div>'
})
export class AppComponent implements OnInit, OnDestroy {
  online = true;
  private unsubscribe?: () => void;

  async ngOnInit() {
    const result = await checkConnectivity();
    this.online = result.online;

    this.unsubscribe = watchConnectivity(
      (result) => this.online = result.online,
      { observe: true }
    );
  }

  ngOnDestroy() {
    this.unsubscribe?.();
  }
}
Previous
Vue
Next
Svelte