Skip to content

Instantly share code, notes, and snippets.

@hoangtranson
Last active June 15, 2020 05:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoangtranson/03a11a590d7c7f6ef56dd2518b3851d7 to your computer and use it in GitHub Desktop.
Save hoangtranson/03a11a590d7c7f6ef56dd2518b3851d7 to your computer and use it in GitHub Desktop.
@Injectable({
providedIn: 'root'
})
export class LoadingInterceptorService {
activeRequests: number = 0;
constructor(
private loadingScreenService: LoadingService
) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (this.activeRequests === 0) {
this.loadingScreenService.startLoading();
}
this.activeRequests++;
return next.handle(request).pipe(
finalize(() => {
this.activeRequests--;
if (this.activeRequests === 0) {
this.loadingScreenService.stopLoading();
}
})
)
};
}
@Jassem
Copy link

Jassem commented May 7, 2020

Apparently, you forgot to implement HttpInterceptor in this class LoadingInterceptorService

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment