我有很简单的功能:

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 变量不包含任何键或值:

未设置 Angular 5 HttpParams-LMLPHP

我究竟做错了什么?

最佳答案

试试这个:

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

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

10-06 12:25