Best Online Tutorials

SQL Tutorial

Free SQL Tutorial

SQL Interview Questions

SQL Practice Questions

SQL Tips & Tricks

SQL Errors

SQL Books

Angular Tutorial

Free Angular Tutorial

Angular Interview Questions

Angular Practice Questions

Angular Tips & Tricks

Angular Errors

Angular Books

Node.js Tutorial

Free Node.js Tutorial

Node.js Interview Questions

Node.js Practice Questions

Node.js Tips & Tricks

Node.js Errors

Node.js Books

React.js Tutorial

Free React.js Tutorial

React.js Interview Questions

React.js Practice Questions

React.js Tips & Tricks

React.js Errors

React.js Books

SSIS Tutorial

Free SSIS Tutorial

SSIS Interview Questions

SSIS Practice Questions

SSIS Tips & Tricks

SSIS Errors

SSIS Books

SEO Tutorial

Free SEO Tutorial

SEO Interview Questions

SEO Practice Questions

SEO Tips & Tricks

SEO Errors

SEO Books

Javascript Tutorial

Free Javascript Tutorial

Javascript Interview Questions

Javascript Practice Questions

Javascript Tips & Tricks

Javascript Errors

Javascript Books

MongoDB Tutorial

Free MongoDB Tutorial

MongoDB Interview Questions

MongoDB Practice Questions

MongoDB Tips & Tricks

MongoDB Errors

MongoDB Books

Next.js Tutorial

Free Next.js Tutorial

Next.js Interview Questions

Next.js Practice Questions

Next.js Tips & Tricks

Next.js Errors

Next.js Books

Angular - Interceptor 

Prashant Surya  |   Nov 4, 2019  |  Views: 14

Description:

Interceptor is the  technique in angular by which we can intercept and modify the each http requests from a single place.

It works as a request handler or middleware.

HttpIntercepror is the Interface used while creating a Intercept.

Why we use:
  • To handle request headers
  • To log request and response
  • To handle Authentication
  • To handle Error
  • To handle Response code
How to create a Interceptor:
@Injectable()
export class MyNewInterceptor implements HttpInterceptor {
  intercept(
    request: HttpRequest<any>, next: HttpHandler
  ) : Observable<HttpEvent<any>> {
    console.log(request.url);
    return next.handle(request);
  }
}
How to register your Interceptor:
Now we have to register it into the providers array in NgModule.

import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { MyNewInterceptor } from './your-path-of-interceptor';
@NgModule({
  imports: [
    HttpClientModule
  ],
  providers: [
    {
      provide: HTTP_INTERCEPTORS,
      useClass: MyNewInterceptor,
      multi: true  //it allows to use multiple Http Interceptors
    },
  ],
})
export class AppModule { }

Read Examples:

Comments:
Content Contributor
Prashant Surya

Prashant Surya

Software developer at Uniserve Data Technologies Pvt. Ltd.  |   Noida, Uttar Pradesh, India

I am a software developer, freelancer and trainer working on technologies likes. MEAN stack, MERN Stack, ASP.NET full stack, WebRTC, socket.io ,PWA, SQL, JavaScript, jQuery, HTML, CSS, SEO, responsive UI/UX designing... having 7 years of experience in development in multiple domains like, eCommerce, RTA, capital markets, education, real estate...


Read related articles

Angular - Ivy

Prashant Surya  |   Dec 18, 2019  |  Views: 6

Angular - Sanitization

Prashant Surya  |   Nov 13, 2019  |  Views: 12

Angular - HttpClient

Prashant Surya  |   Nov 4, 2019  |  Views: 15

Angular - *ngFor

Prashant Surya  |   Nov 4, 2019  |  Views: 13

Angular - ng-switch

Prashant Surya  |   Nov 4, 2019  |  Views: 19

Angular - ng-template

Prashant Surya  |   Nov 4, 2019  |  Views: 11

Angular - ng-content

Prashant Surya  |   Nov 4, 2019  |  Views: 13

Angular - ng-container

Prashant Surya  |   Nov 4, 2019  |  Views: 17

Angular - ElementRef

Prashant Surya  |   Nov 4, 2019  |  Views: 18

Angular - HostBinder

Prashant Surya  |   Nov 4, 2019  |  Views: 25

Angular - HostListner

Prashant Surya  |   Nov 4, 2019  |  Views: 30

Angular - Interceptor

Prashant Surya  |   Nov 4, 2019  |  Views: 15

Angular - ControlValueAccessor

Prashant Surya  |   Nov 4, 2019  |  Views: 21

Angular - ViewEncapsulation

Prashant Surya  |   Nov 4, 2019  |  Views: 6

Angular - Error Handling

Prashant Surya  |   Nov 4, 2019  |  Views: 10

Angular - Animations

Prashant Surya  |   Nov 4, 2019  |  Views: 11

Angular - Rxjs

Prashant Surya  |   Nov 4, 2019  |  Views: 8

Angular - Observable

Prashant Surya  |   Nov 4, 2019  |  Views: 19

Angular - Pipe

Prashant Surya  |   Nov 4, 2019  |  Views: 23

Angular - Form Validation

Prashant Surya  |   Nov 4, 2019  |  Views: 18

Angular - Forms

Prashant Surya  |   Nov 4, 2019  |  Views: 12

Angular - Lazy Loading

Prashant Surya  |   Nov 4, 2019  |  Views: 21

Angular - Guard

Prashant Surya  |   Nov 4, 2019  |  Views: 14

Angular - Auxilary Routes

Prashant Surya  |   Nov 4, 2019  |  Views: 18

Angular - Routing

Prashant Surya  |   Nov 4, 2019  |  Views: 14

Angular - Data Binding

Prashant Surya  |   Nov 4, 2019  |  Views: 21

Angular - Typescript

Prashant Surya  |   Nov 4, 2019  |  Views: 11

Angular - Dependency Injection

Prashant Surya  |   Nov 4, 2019  |  Views: 20

Angular - Service

Prashant Surya  |   Nov 4, 2019  |  Views: 14

Angular - Directive

Prashant Surya  |   Nov 4, 2019  |  Views: 14

Angular - Decorators

Prashant Surya  |   Nov 4, 2019  |  Views: 26

Angular - Module

Prashant Surya  |   Nov 3, 2019  |  Views: 46

Angular - Component

Prashant Surya  |   Nov 3, 2019  |  Views: 57

Angular - Life Cycle

Prashant Surya  |   Nov 3, 2019  |  Views: 48

Angular - Compilation

Prashant Surya  |   Nov 3, 2019  |  Views: 66

Angular - Building blocks

Prashant Surya  |   Nov 3, 2019  |  Views: 62

Angular - Benefits

Prashant Surya  |   Nov 3, 2019  |  Views: 69

Angular - Installation

Prashant Surya  |   Nov 2, 2019  |  Views: 203

Angular - Introduction

Prashant Surya  |   Nov 2, 2019  |  Views: 487

Want to sell your software ?-

If you want to sell your readymade software to the genuine clients or businessman, list your software with details and demo links.

  • Sell ERP
  • Sell Website Clones
  • Sell App Clones
  • Sell Readymade Portals
  • Sell Readymade Websites
  • Sell Mobile Apps
  • Sell Window Apps

Clients will find it using our advanced search filter and will contact you directly.

No any charge for the product lsiting.

Do you own a Company ?+

Property.sale

Buy or Sell Commercial Property+

Are you a freelancer ?+

Looking for a job ?+

Are you a Service Provider ?+

Are you a blogger ?+

Do you own an IT Institute ?+



Property.sale