Here the interceptor I've written to handle the spinner directly via the interceptor
@Injectable()
export class ApiInterceptor implements HttpInterceptor {
constructor(private _globalSpinnerService: GlobalSpinnerService) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const spinnerParam: string = req.params.get("spinner")
let handleObs: Observable<HttpEvent<any>> = next.handle(req)
if(spinnerParam) {
this._globalSpinnerService.spinner = true
handleObs.toPromise().then(() => {
this._globalSpinnerService.spinner = false
})
}
return handleObs
}
}
It's working as expected. However, I now see all my requests involving the spinner getting sent twice. So I guess my way to remove the spinner isn't the neatest. How can I tell my interceptor to remove my spinner once the handle is over ?
EDIT:
I changed the code by replacing my handleObs.toPromise().then
by handleObs.do()
and it's now working fine. I am just not sure why