Angular 5 个 HttpParams 未设置

Angular 5 HttpParams not being set

我有非常简单的功能:

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;
}

当我调试这个时,params 变量不包含任何键或值:

我做错了什么?

试试这个:

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

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.