A lightweight Angular service for monitoring network connectivity and reachability in your Angular applications.
npm install @adplorg/angular-reachabilityA lightweight Angular service for monitoring network connectivity and reachability in your Angular applications.
- Check if a specific URL is reachable
- Monitor online/offline status changes
- Simple and easy to use API
- TypeScript support
- Angular 19 compatible
``bash`
npm install @adplorg/angular-reachability
`typescript
import { AngularReachabilityService } from '@adplorg/angular-reachability';
@Component({
selector: 'app-root',
template: '...'
})
export class AppComponent {
constructor(private reachability: AngularReachabilityService) {}
}
`
`typescript`
async checkConnection() {
try {
const isReachable = await this.reachability.isReachable('https://api.example.com');
if (isReachable) {
console.log('URL is reachable');
} else {
console.log('URL is not reachable');
}
} catch (error) {
console.error('Error checking reachability:', error);
}
}
`typescript`
monitorOnlineStatus() {
this.reachability.onConnect().subscribe(message => {
console.log(message); // "you are online"
});
}
`typescript`
monitorOfflineStatus() {
this.reachability.onDisconnect().subscribe(message => {
console.log(message); // "you are offline"
});
}
: The URL to check for reachability
- Returns: Promise that resolves to true if the URL is reachable, false` otherwise- Angular 19.x
- TypeScript 5.x
- RxJS 7.x
MIT
For support, please open an issue in the GitHub repository.