How can httpParams quickly add parameters?

the method of adding parameter content to httpParams. The official way to write it is:

const httpParams = new HttpParams().set(key,value).set(key,value).set(key.value);

if you want to add multiple parameters, you have to keep .set (), which feels troublesome, and then comes up with an optimized way to write it:

let data = {
    aaa:"aaa",
    bbb:"bbb",
}
const httpParams = new HttpParams();
for(let key in data){
    httpParams.set(key,data[key]);
}

but if you do this, the parameters will not be passed in. Why, is there any solution?

Feb.28,2021

const httpParams = new HttpParams();
for(let key in data){
    httpParams = httpParams.set(key,data[key]);
}

Don't bother, just shove your value into the constructor

const httpParams = new HttpParams({
    fromObject: data
});
Menu