13

I have thins very simple function:

createParams(paramsArray, withToken: boolean): HttpParams {
    let params = new HttpParams();
    let currentUser = JSON.parse(localStorage.getItem('currentUser'));
    params.set('access_token', JSON.stringify(currentUser.token));
    return params;
}

When i debug this the params variable does not contain any keys nor values:

enter image description here

What am i doing wrong?

Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60
Marc Rasmussen
  • 19,771
  • 79
  • 203
  • 364

1 Answers1

30

Try this:

let Params = new HttpParams();
Params = Params.append('access_token', JSON.stringify(currentUser.token));

OR

let params = new HttpParams().set('access_token', JSON.stringify(currentUser.token)); 

HttpParams is intended to be immutable. The set and append methods don't modify the existing instance. Instead they return new instances.

Hasan Fathi
  • 5,610
  • 4
  • 42
  • 60