【发布时间】:2017-11-27 11:12:13
【问题描述】:
我在 angular 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
}
]
}
url 传递为 http://localhost:3000/sample/[object%20Object]
还有 404 错误。我该如何纠正这个问题?
【问题讨论】:
标签: json angular rest http http-status-code-404