Angular2可以通过http方法删除发送json正文吗?
我尝试了,它说错误
ORIGINAL EXCEPTION: options.search.clone is not a function
service.ts
deletetag(tagid: number): Observable<any> {
let body = JSON.stringify(
{
"token": "test",
"content": {
"tagId": tagid
}
}
);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.delete("http://localhost:8080/backend/tag", body, options)
.map(res => this.extractData(res))
.catch(this.handleError);
}
component.ts
this.tagService.deletetag(1)
.subscribe(
data => { },
error => { },
() => { }
);
答案 0 :(得分:9)
根据RequestOptionsArgs interface和Http delete函数参数,我认为您需要发送删除请求,如下所示:
deletetag(tagid: number): Observable<any> {
let body = JSON.stringify(
{
"token": "test",
"content": {
"tagId": tagid
}
}
);
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({
headers: headers,
body : body
});
return this.http.delete("http://localhost:8080/backend/tag", options)
.map(res => this.extractData(res))
.catch(this.handleError);
}