Skip to content

VadimDez/ngx-online-status

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ngx-online-status

Downloads Build Status https://www.paypal.me/vadimdez

Detect online/offline state

Angular 5+ Module to track online and offline state

Demo

https://vadimdez.github.io/ngx-online-status/

or stackblitz code/demo

https://stackblitz.com/edit/ngx-online-status

Install

npm install ngx-online-status --save

Usage

  1. Import OnlineStatusModule to your module
import { OnlineStatusModule } from 'ngx-online-status';

@NgModule({
  declarations: [
    // ...
  ],
  imports: [
    OnlineStatusModule
  ],
  providers: [
    //...
  ]
})
  1. Inject OnlineStatusService and use it:
import { OnlineStatusService, OnlineStatusType } from "ngx-online-status";

export class AppComponent {
  status: OnlineStatusType = this.onlineStatusService.getStatus(); // get initial status

  constructor(private onlineStatusService: OnlineStatusService) {
    this.onlineStatusService.status.subscribe((status: OnlineStatusType) => {
      // use status
      this.status = status;
    });
  }
}
OnlineStatusType

OnlineStatusType.OFFLINE equals to 0

OnlineStatusType.ONLINE equals to 1

License

MIT ยฉ Vadym Yatsyuk