0

Is there a way to only apply the angular http interceptor to calls in a certain shared module or for certain individual services?

2
  • 1
    You can maybe check the if the req.url is equal to the path/paths you want to treat differently. Commented Aug 24, 2022 at 5:42
  • HttpContext Commented Aug 25, 2022 at 3:20

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.