Last active
June 15, 2020 05:02
-
-
Save hoangtranson/03a11a590d7c7f6ef56dd2518b3851d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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(); | |
} | |
}) | |
) | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apparently, you forgot to implement HttpInterceptor in this class LoadingInterceptorService