我在角度2中使用http.delete。这是我的代码
app.component.ts
deleteCourse(id: string) {
console.log(id);
this.appService.deleteByID(id)
.subscribe(x => {console.log(x); this.fetchCourseData(); }
);
}
app.service.ts
deleteByID(id: string): Observable<string>
let options1 = new RequestOptions();
options1.headers = new Headers();
options1.headers.append('Content-Type', 'application/json');
return this.http.delete('http://localhost:3000/sample'+ '/' + id , options1)
.map((response: Response) => {
const result = response.json();
return result; });
}
db.json
{
"sample": [
{
{
"courseTitle": "ggg",
"courseDescription": "ggg",
"courseCredit": "2",
"id": 8
},
{
"courseTitle": "ggg",
"courseDescription": "ggg",
"courseCredit": "1",
"id": 9
},
{
"courseTitle": "add",
"courseDescription": "asdas",
"courseCredit": "2",
"id": 10
}
]
}
网址传递为 http://localhost:3000/sample/[object%20Object]
以及404错误。我如何纠正这个问题?