Check internet connection in web using Angular 4

We don’t need any libraries for this however public onlineOffline: boolean = navigator.onLine; will do the trick but this is just a one time check. We need to treat this value as an observable so whenever the online status change we are updated. For this rxjs will help. Import these import { Observable, Observer, fromEvent, … Read more

Angular show spinner for every HTTP request with very less code changes

@jornare has a good idea in his solution. He’s handling the case for multiple requests. However, the code could be written simpler, without creating new observable and storing requests in memory. The below code also uses RxJS 6 with pipeable operators: import { Injectable } from ‘@angular/core’; import { HttpRequest, HttpHandler, HttpInterceptor, HttpResponse } from … Read more

Format number of seconds as mm:ss in Angular 2

Angular Date Pipe works with number value too, But please note: Only with milliseconds. If you want to get mm:ss(00:00) you need to convert your number value to milliseconds. In your case it should be: 3600 * 1000 <div class=”time-box” *ngIf=”p.value.playerTimer > 0″> {{ p.value.playerTimer * 1000 | date:’mm:ss’ }} </div> here is the Stackblitz … Read more

Unhandled Promise rejection: Cannot match any routes

I had the same problem recently. It was caused by a call to router.navigate inside the ngOnInit method of a component. The test was trying to create the component, but inside ngOnInit it was attempting to navigate away from the component (because certain conditions were not met). In my case, I am importing the RouterTestingModule … Read more