File

projects/maplander/core/src/lib/interceptors/loader/browser-loader.interceptor.ts

Index

Methods

Constructor

constructor(_loader: LoaderService)
Parameters :
Name Type Optional
_loader LoaderService No

Methods

intercept
intercept(req: HttpRequest, next: HttpHandler)
Parameters :
Name Type Optional
req HttpRequest<any> No
next HttpHandler No
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);
      }));
  }
}

result-matching ""

    No results matching ""