我正在使用Angular和APIC工具包连接REST Api。我想发布反馈,但不幸的是它显示如下错误:
Response {_body: "{"error":{"statusCode":422,"name":"ValidationError…esence"]},"messages":{"id":["can't be blank"]}}}}", status: 422, ok: false, statusText: "Unprocessable Entity", headers: Headers, …}
这意味着id不能为空,但是根据用户体验,将id放在平台上是不可行的。
以下是代码:
service.ts:
// API: POST /Feedbacks
createFeedback(feedback: Feedback): Observable<Feedback>{
let url = API_URL + '/Feedbacks';
return this.http.post(url + "/", feedback, this.options)
.map(res => res.json())
.catch(err => {
return Observable.throw(err);
});
}
component.ts:
feedback = {};
addFeedback(feedback:Feedback){
this.accountService.createFeedback(feedback)
.subscribe(res => {
feedback.id = undefined;
this.feedback = res as Feedback;
console.log(res);
}, err => {
console.log(err);
});
}
解决此问题的任何解决方案?