私のプロジェクトはオンプレミスサーバを使用しています。バックエンドは.NETコアで動作し、私はバックグラウンドのインスタンスを実行できません。したがって私はin-memory-web-apiを使用する私のプロジェクトのための別々の(角をつけた)環境を作りました。angular2 http.delete on in-memory-web-api
私はそれを設定して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();
})
}
});
}
私のコンポーネントの機能を追加するのを忘れました、今ここにそれを追加しました。私はloadSubscribeを呼び出します。 – MiVvlt