File

projects/maplander/core/src/lib/interceptors/state/server-state.interceptor.ts

Index

Methods

Constructor

constructor(_transferState: TransferState)
Parameters :
Name Type Optional
_transferState TransferState No

Methods

intercept
intercept(req: HttpRequest, next: HttpHandler)
Parameters :
Name Type Optional
req HttpRequest<any> No
next HttpHandler No
Returns : Observable<HttpEvent<any>>
import {tap} from 'rxjs/operators';
import { Injectable } from '@angular/core';
import { HttpEvent, HttpInterceptor, HttpHandler, HttpRequest, HttpResponse } from '@angular/common/http';
import { TransferState, makeStateKey } from '@angular/platform-browser';
import { Observable } from 'rxjs';

@Injectable()
export class ServerStateInterceptor implements HttpInterceptor {

  constructor(
    private _transferState: TransferState,
  ) {}

  intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req).pipe(tap(event => {
      if (event instanceof HttpResponse) {
        this._transferState.set(makeStateKey(req.url), event.body);
      }
    }));
  }
}

result-matching ""

    No results matching ""