2

I'm adding custom params for API's for some use case which is not require to send it BE and I want to delete them before sending to BE.

Url: https://www.dummy.com?reload=true
params: req.params.delete('reload')

Deleting 1 param (reload) working fine.

Url: https://www.dummy.com?create=true&reload=true&some=false
I want remove "reload" and "some"

params: ???

Interceptor code

auth = req.clone({
  url: `${baseUrl}${req.url}`,
  headers,
  params: req.params.delete('reload')
})
Arun M
  • 133
  • 1
  • 11

1 Answers1

1

Params is immutable. The delete method does not modify the original object, but constructs new object with the param deleted.

params.delete:

Construct a new body with either the given value for the given parameter removed, if a value is given, or all values for the given parameter removed if not.

req.params = req.params.delete('reload');
req.params = req.params.delete('some');

auth = req.clone({
  url: `${baseUrl}${req.url}`,
  headers
})
Joosep Parts
  • 5,372
  • 2
  • 8
  • 33
  • Getting error "Cannot assign to 'params' because it is a read-only property" – Arun M Aug 06 '22 at 04:56
  • Ah yes, TS might scream at this. Ignore it or don't set the params with undesired options in the first place. Edit the params before making the request (instead of editing them in the inceptor). – Joosep Parts Aug 06 '22 at 05:11
  • we have some common logic inside interceptor, after performing it i'm deleting these params. – Arun M Aug 06 '22 at 06:03