为什么我的http.put不能在Angular中工作



我正在使用dx-gata网格来更新数据库。我有一个post和delete可以正常工作,但当我尝试使用http.post更新现有行时,它不起作用。网格已成功更新,但刷新后该行实际上尚未更新。

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方法

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));
}

据我所知,您正在订阅响应,但没有使用中执行任何操作。您只显示了一条toast消息。

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.');
});

最新更新