【发布时间】:2017-11-03 11:43:49
【问题描述】:
我需要关于我的个人项目的帮助。我正在尝试使用 Angular HTTP post 方法然后我得到了这种错误。当我添加新数据时,调用addStudent 并重新加载页面,semester 列返回/显示[object Object]。除semester 外,其他列均正常工作。
//file name: app.service.ts
addStudent(newId: string, newName: string, newYear: string, newSemester: string, newScore: string): Observable<any>
{
return this.http.post("http://localhost:3000/Student", {id: newId, name: newName, year: newYear, semester: newSemester, score: newScore});
}
//file name : app.component.ts
addStudent(newId: string, newName: string, newYear: string, newSemester: string, newScore: string)
{
this.stockService.addStudent(newId, newName, newYear, newSemester, newScore).subscribe();
console.log(newSemester);
}
<!--file name: app.component.html-->
<tr *ngFor="let Student of Student" [attr.id]="Student.id">
<td>{{Student.id}}</td>
<td>{{Student.name}}</td>
<td>{{Student.year}}</td>
<td>{{Student.semester}}</td>
<td>{{Student.score}}</td>
</tr>
</table>
</h1>
<h3>ADD NEW</h3>
<br>ID: <input #newId/>
<br>Name: <input #newName/>
<br>Year: <input #newYear/>
<br>Semester: <input #newSemester/>
<br>Score: <input #newScore/>
<br><button type="button" role="button" (click)="addStudent(newId.value, newName.value, newYear.value, newSemester, newScore.value)">ADD</button>
添加新行时 Json 看起来像这样
{
"id": "a",
"name": "a",
"year": "a",
"semester": {},
"score": "a"
}
如果需要更多的 sn-ps,请告诉我。
谢谢。
【问题讨论】:
标签: angular typescript html-table angular-http