Is there a way to only apply the angular http interceptor to calls in a certain shared module or for certain individual services?
Asked
Active
Viewed 1,342 times
0
-
1You can maybe check the if the `req.url` is equal to the path/paths you want to treat differently. – callback Aug 24 '22 at 05:42
-
[HttpContext](https://angular.io/api/common/http/HttpContext) – Eddy Lin Aug 25 '22 at 03:20
1 Answers
1
It's not possible to set up your own service based interceptors. However, you can pass data with each request and simply check in the interceptor for that condition.
You could pass like a query param or set a custom header for that request to be checked against.
if (headers.has('my-custom-header')) {
headers=headers.append('content-type','application/json')
}
And then in the file where you are calling the request, you could pass in the custom header you are configuring
let headers = new HttpHeaders()
headers=headers.append('my-custom-header', 'true')
Here's also another more detailed answer https://stackoverflow.com/a/50625945/15492085

DOZBORNE
- 560
- 3
- 13