bb-itag-angular-connection-service v2.0.3
BbItagAngularConnectionService
The credit for this software goes to the original creator of the library:
ultrasonicsoft/ng-connection-service
I just create my own project as the update of the npm package was taken to long for me.
Internet Connection Monitoring Service (Angular v9)
Detects whether browser has an active internet connection or not in Angular application.
Install
You can get it on npm.
npm install ng-connection-service --save
Usage
- Inject
ConnectionService
in Angular component's constructor. - Subscribe to
monitor()
method to get push notification whenever internet connection status is changed.
import { Component } from '@angular/core';
import { ConnectionService } from 'connection-service';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
status = 'ONLINE';
isConnected = true;
constructor(private connectionService: ConnectionService) {
this.connectionService.monitor().subscribe(isConnected => {
this.isConnected = isConnected;
if (this.isConnected) {
this.status = "ONLINE";
}
else {
this.status = "OFFLINE";
}
})
}
}
Demo
License
MIT License © Balram Chavan
This library was generated with Angular CLI version 9.0.0.
Code scaffolding
Run ng generate component component-name --project bb-itag-angular-connection-service
to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module --project bb-itag-angular-connection-service
.
Note: Don't forget to add
--project bb-itag-angular-connection-service
or else it will be added to the default project in yourangular.json
file.
Build
Run ng build bb-itag-angular-connection-service
to build the project. The build artifacts will be stored in the dist/
directory.
Publishing
After building your library with ng build bb-itag-angular-connection-service
, go to the dist folder cd dist/bb-itag-angular-connection-service
and run npm publish
.
Running unit tests
Run ng test bb-itag-angular-connection-service
to execute the unit tests via Karma.
Further help
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.
5 years ago