I'm trying to send the form data updated user data but not how it does not work

{ "name":"User", "status":1 }

How to say Angular what is it

<input type="text" [value]="user.name" name="name">

This is Input

service.ts

 updateProductData(dataUrl, id){ let url = ${environment.endpoint}/${dataUrl}/${id} ; let header = new HttpHeaders() .set("Authorization", "Bearer " + this.token) .set("Accept", "application/json"); return this.http.put(url, { "name":"User", "status":1 },{ headers: header }); } 
  • Your code is not very relevant. Look in the logs of the browser and it will explain to you what is wrong. What I have noticed is that your url not a string to use string templates, use the `character at the beginning and end of the line. Add an Observable <Response> response to functions. And where you call it, use the subscribe () method. - GVArt

1 answer 1

service.ts

 updateProductData(dataUrl, id): Observable<any> { const url = `${environment.endpoint}/${dataUrl}/${id}`; const header = new HttpHeaders() .set('Authorization', 'Bearer ' + this.token) .set('Accept', 'application/json'); return this.http.put(url, { 'name': 'User', 'status': 1 }, { headers: header }); } 

component.ts

 private dataSub: Subscription; update() { if (this.dataSub && !this.dataSub.closed) { this.dataSub.unsubscribe(); } this.dataSub = this.service.updateProductData('url', 1) .subscribe((res: any) => { console.log(res); }, (err) => { console.log(err); }); }