You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
644 B
TypeScript
19 lines
644 B
TypeScript
|
3 weeks ago
|
import { Injectable } from '@angular/core';
|
||
|
|
import { HttpRequest, HttpHandler, HttpEvent, HttpInterceptor } 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(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
|
||
|
|
this.loadingService.showLoader();
|
||
|
|
|
||
|
|
return next.handle(request).pipe(
|
||
|
|
finalize(() => this.loadingService.hideLoader())
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|