What are Http Interceptors?
Http Interceptors are part of @angular/common/http, which inspect and transform HTTP requests from your application to the server and vice-versa on HTTP responses. These interceptors can perform a variety of implicit tasks, from authentication to logging.
The syntax of HttpInterceptor interface looks like as below,
interface HttpInterceptor {intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>;}
You can use interceptors by declaring a service class that implements the intercept() method of the HttpInterceptor interface.
@Injectable()export class MyInterceptor implements HttpInterceptor {constructor() {}intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {...}}
After that you can use it in your module,
@NgModule({...providers: [{provide: HTTP_INTERCEPTORS,useClass: MyInterceptor,multi: true}]...})export class AppModule {}
August 14, 2022
286
Read more
What is Angular Framework?
November 04, 2022
AngularWhat is a Angular module?
November 03, 2022
AngularWhat are the steps to use animation module?
October 31, 2022
Angular