How do I send form data in an HTTP PUT request to Angular 4?
I am trying to send the form data to the updated user data but not as it fails
{
"name":"User",
"status":1
}
How to tell Angular that it is
<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
});
}
0
Author: Ara Chinaryan, 2017-11-21
1 answers
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);
});
}
0
Author: Sidal, 2018-04-06 13:03:28