loader-interceptor.ts Loader has been added in Interceptor. In the below upload() function I wouldn't want my loader to get started. The loader should not be applied to that particular method alone.
export class LoaderInterceptorService implements HttpInterceptor {
constructor(private loaderService: LoaderService) { }
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.loaderService.show();
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
this.loaderService.show();
return next.handle(req).pipe(map(event => {
if (event instanceof HttpResponse) {
this.loaderService.hide();
}
return event;
}));
}
}
}
loader.service.ts This method has 2 methods one to start and stop the spinner.
export class LoaderService {
isLoading = new Subject<boolean>();
constructor() { }
show() {
this.isLoading.next(true);
}
hide() {
this.isLoading.next(false);
}
}
Myuploadservice.ts
In the below method when I call upload() method I don't want my loader to be loaded.
upload(file: File,id) {
const formdata: FormData = new FormData();
formdata.append('file', file);
return this.http.post(`${this.baseURL}/fileupload/${id}`, formdata,{
reportProgress: true,
observe: 'events'
});
}