How to set the params in http options with key and value by passing id dynamically as received from the serve r in calling the API

I am stucking in set the params in http options in calling the API ,it is showing the errors that no overload is required and also *An object literal cannot have multiple properties with the same name in strict mode.*I want to set the params in calling the API.

.service.ts

senrstart( token) {   let httpOptions = {     headers: new HttpHeaders({       'Content-Type': 'application/json',       'Authorization': 'Token ' + token     }),    params: new HttpParams()         params.set('id', this.jammers.name)     }       this.http.get(environment.apiUrl+'/api/sensors/start?id', httpOptions).subscribe(     (senrst:any[])=>{       localStorage.setItem("senrst",JSON.stringify(senrst));     console.log("senrstart:",JSON.parse(localStorage.getItem("senrst"))) 

.component.ts

senrstart(){   this.senrstart=JSON.parse(localStorage.getItem("senrstart")); console.log("senrstart",this.senrstart) } 

For the above code I want to set the params by passing the id dynamically with key:id and value is sensor.name which I recieved from backend.

Add Comment
1 Answer(s)

The params should be in one line?

params: new HttpParams().set('id', this.jammers.name) 
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.