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.
Detects whether browser has an active internet connection or not in Angular application.
You can get it on npm.
npm install ng-connection-service --save
- 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";
}
})
}
}
MIT License © Balram Chavan
This library was generated with Angular CLI version 9.0.0.
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.
Run ng build bb-itag-angular-connection-service
to build the project. The build artifacts will be stored in the dist/
directory.
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
.
Run ng test bb-itag-angular-connection-service
to execute the unit tests via Karma.
To get more help on the Angular CLI use ng help
or go check out the Angular CLI README.