'Why is my http.put not working in Angular?
I am making use of a dx-gata-grid to update a db. I have a post and delete that are working as expected but when I try to update an existing row using an http.post it does not work. The grid successfully updates but when refreshed the row hasn't actually updated.
Datagrid OnRowUpdate
onRowUpdating(e) {
const gridData = e;
const row = {
name: gridData.newData.name || gridData.oldData.name,
expression: gridData.newData.expression || gridData.oldData.expression,
longterm: gridData.newData.longterm || gridData.oldData.longterm,
persisted: gridData.newData.persisted || gridData.oldData.persisted,
status: gridData.newData.status || gridData.oldData.status
};
this.RowManagerService.updateRow(gridData.oldData.id, row)
.pipe(takeUntil(this.unsubscribe))
.subscribe((data: any) => {
this.toastMessageService.showSuccess(' Successfully Updated Row');
}, (error) => {
this.toastMessageService.showFailure(' Something went wrong when updating the Row.');
});
}
updateRow method
updateRow(rowID, data): Observable<any> {
const endPoint = this.formatString(this.url + '/update/${id}', {
id: rowID,
});
return this.http.put<any>(this.requestUrl + endPoint, data, {headers: this.headers})
.pipe(map((response: any) => {
return response;
}),
catchError(this.error));
}
Solution 1:[1]
As far as i can see you are subscribing to the response but you are not doing anything with in. You only show a toastmessage.
this.RowManagerService.updateRow(gridData.oldData.id, row)
.pipe(takeUntil(this.unsubscribe))
.subscribe((data: any) => { // YOU NEED TO DO SOMETHING WITH THIS DATA!
this.toastMessageService.showSuccess(' Successfully Updated Row');
RETURN DATA;
}, (error) => {
this.toastMessageService.showFailure(' Something went wrong when updating the Row.');
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mustapha Afkir |
