Angular 2 Interceptors | ng2-interceptors

Concept of Interceptors is used for intercepting the HTTP request and response in Angular 2. You can append values in your HTTP request before sending to the server. You can alter you server response before displaying it.

For example in every request you wanted to show a loader and after coming response from server you wanted to hide the loader this show and hide of loader can be manage with Interceptors.

If you wanted to send some authentication token in headers you can manage it through Interceptors.

Because we are intercepting the HTTP request here so we also can name it "HTTP Interceptors".

For using intercepters you need to install NPM intercepter module and for that run below command:


app.module.ts


ServerURLInterceptor.ts

user.service.ts

 

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *