ngx-online-status
v2.0.0
Published
Online status events for angular
Downloads
12,147
Maintainers
Readme
ngx-online-status
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
- Import
OnlineStatusModule
to your module
import { OnlineStatusModule } from 'ngx-online-status';
@NgModule({
declarations: [
// ...
],
imports: [
OnlineStatusModule
],
providers: [
//...
]
})
- 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