import { Injectable } from '@angular/core';
      import { HttpInterceptor, HttpEvent, HttpHandler, HttpRequest } from '@angular/common/http';
      import { Observable } from 'rxjs';
      
      @Injectable()
      export class YourInterceptor implements HttpInterceptor {
        intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
          return next.handle(req);
        }
      }

      Typescript language logo
      your recipe card header background
      Angular HttpInterceptor Empty

      Angular snippets for TypeScript

      The @Injectable() decorator registers the YourInterceptor class as a HTTP interceptor. The intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> function takes a req object and returns an Observable that emits HttpEvent objects. The handle(req: HttpRequest<any>) function of the next object receives a req object and calls the handle() method of the HttpHandler object that was passed as an argument.

      Shortcut: a_http_interceptor

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.