gpt4 book ai didi

http - angular2 http.delete on-memory-web-api

转载 作者:搜寻专家 更新时间:2023-10-30 21:51:35 24 4
gpt4 key购买 nike

我的项目使用本地服务器,后端在 .NET Core 上运行,我在 Mac 上开发,所以我无法运行后端的实例。因此,我为使用 in-memory-web-api 的项目创建了一个单独的 (angular-cli) 环境。

我已将其设置好并适用于 get/和 get/:id。但删除不起作用。有什么方法可以使这项工作起作用,或者不能用 i-m-w-a 做到这一点?

服务

public getOperations(): Observable<IOperation[]>{
return this.http.get(`${environment.baseUrl}operations/`)
.map(this.sharedService.extractData)
.catch(this.sharedService.handleError);
}
public getOperation(operationId: string):Observable<IOperation>{
return this.http.get(`${environment.baseUrl}operations/${operationId}`)
.map(this.sharedService.extractData)
.catch(this.sharedService.handleError);
}
public deleteOperation(operationId: string): Observable<any>{
return this.http.delete(`${environment.baseUrl}operations/${operationId}`)
.map(this.sharedService.extractData)
.catch(this.sharedService.handleError);
}

内存数据库

export class InMemoryDataService implements InMemoryDbService {
createDb() {
let operations: IOperation[] = [
new Operation({
id:'001',
name: 'Operation ABC',
status:'Active',
startDate: new Date().toLocaleDateString()
}),
new Operation({
id:'002',
name: 'Operation DEF',
status:'Closed',
startDate: new Date().toLocaleDateString(),
endDate: new Date().toLocaleDateString()
}),
new Operation({
id:'003',
name: 'Operation GHI',
status:'Closed',
startDate: new Date().toLocaleDateString(),
endDate: new Date().toLocaleDateString()
}),
new Operation({
id:'004',
name: 'Operation JKL',
status:'Closed',
startDate: new Date().toLocaleDateString(),
endDate: new Date().toLocaleDateString()
}),
];
return {operations};
}
}

忘记添加调用我的服务方法的组件方法:

public deleteOperation(operation: IOperation){
this.confirmationService.confirm({
message: `Are you sure that you want to delete '${operation.name}'?`,
accept: () => {
this.operationsService.deleteOperation(operation.id)
.subscribe(()=>{
this.loadOperations();
})
}
});
}

最佳答案

好的,我找到问题了,我从 deleteOperation 服务方法中删除了 .map 函数。extractData 执行了 res.json(),但它不起作用,因此失败了。

关于http - angular2 http.delete on-memory-web-api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42840290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com