projects/maplander/core/src/lib/interceptors/loader/browser-loader.interceptor.ts
Methods |
constructor(_loader: LoaderService)
|
||||||
Parameters :
|
intercept | |||||||||
intercept(req: HttpRequest
|
|||||||||
Parameters :
Returns :
Observable<HttpEvent<any>>
|
import {Injectable} from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http';
import { Observable} from 'rxjs';
import {tap} from 'rxjs/internal/operators';
import {LoaderService} from './loader.service';
@Injectable()
export class LoaderInterceptor implements HttpInterceptor {
constructor(
private _loader: LoaderService
) { }
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this._loader.setProgress(true);
return next.handle(req).pipe(tap((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
this._loader.setProgress(false);
}
},
() => {
this._loader.setProgress(false);
}));
}
}