Angular CLI HttpParams how to delete the params
Asked Answered
C

1

7

I am using angular CLI.
How to delete the token param name and value?

let params = new HttpParams();
    params = params.append('siteId', 1);
    params = params.append('orgId', 2);
    params = params.append('token', 3);

This is my code so far:

validate(email) { 
  let params = new HttpParams(); 
  params = params.set('email', email); 
  params = params.set('siteId', this._global.SITEID); 
  params = params.set('orgId', this._global.ORGID); 
  params = params.set('domainName', this._global.DOMAIN_NAME); 
  params = params.set('token', this._global.getRandomUuid()); 
  params.delete('domainName',this._global.DOMAIN_NAME); 
  return this.api.call('member/duplicate', params); 
} 

call(url, params) { 
  // here I want to delete the token param name and value. 
}
Cincture answered 10/9, 2018 at 13:59 Comment(1)
maybe add some more information and context what you are doing and you might get answers. Your problem description seems quite minimalistic to me. For guidance please check the how to ask page and how to create a minimal example pageEnterovirus
M
5

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.

Example:

params = params.delete('token');

Just writing params.delete('token') will not update the params object because params is immutable. The delete method does not modify the original object, but constructs new object with the param deleted.

Mapes answered 10/9, 2018 at 18:32 Comment(2)
It's not read-only. It was created using the let keyword not constMapes
Thanks man! Your answer really helped me! I've never read the 'returns' section from documentation. After I've read your answer I checked the docs and yeah, there was all there :)) Thanks again!Telespectroscope

© 2022 - 2024 — McMap. All rights reserved.