network-status-angular

Service for angular 6 to detect if the browser has network connection

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
network-status-angular
1.0.44 years ago4 years agoMinified + gzip package size for network-status-angular in KB

Readme

Service for angular 6 to detect if the browser has network connection.
Instalation
npm install network-status-angular
In app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { NetworkStatusAngularModule } from 'network-status-angular';
 
@NgModule({
  imports: [
    BrowserModule,
    // add NetworkStatusAngularModule in imports
    NetworkStatusAngularModule.forRoot()
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}
Usage
In order to use NetworkStatusService, it's necessary to init in one of your component, for example in app.component.ts.
import { Component } from '@angular/core';
    import { NetworkStatusAngularService } from 'network-status-angular';
    
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css']
    })
    export class AppComponent {
      constructor(private networkStatusAngularService: NetworkStatusAngularService) {
        this.networkStatusAngularService.status.subscribe(status => {
          console.log(status); // returns true if it is online or false if it is offline
        });
      }
    }