flare / flare-ui /src /app /interceptors /loading.interceptor.ts
ciyidogan's picture
Upload 118 files
9f79da5 verified
raw
history blame contribute delete
845 Bytes
import { Injectable } from '@angular/core';
import { HttpInterceptor, HttpRequest, HttpHandler, HttpEvent } from '@angular/common/http';
import { Observable } from 'rxjs';
import { finalize } from 'rxjs/operators';
import { LoadingService } from '../services/loading.service';
@Injectable()
export class LoadingInterceptor implements HttpInterceptor {
constructor(private loadingService: LoadingService) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// Skip loading for certain requests
const skipLoading = req.headers.has('X-Skip-Loading');
if (!skipLoading) {
this.loadingService.show();
}
return next.handle(req).pipe(
finalize(() => {
if (!skipLoading) {
this.loadingService.hide();
}
})
);
}
}