angular - Angular displays only ID number from Java REST
问题描述
I am making CRUD app with SpringBoot and Angular. I am using MySQL to this, and when I make POST request in Postman I can see all my date displayed in JSON file. So in Angular I have service with:
export class GetdataService {
constructor(private http: HttpClient) {}
getAllTodos() {
return this.http.get < Todo[] > ('http://wwww.localhost:8081/todos');
}
}
My Component where I am saving data:
export class TaskListComponent implements OnInit {
todos: Todo[];
constructor(private getDataService: GetdataService) {}
ngOnInit() {
this.refreshTodos();
}
refreshTodos() {
console.log(this.getDataService.getAllTodos().subscribe(
response => {
console.log(response);
this.todos = response;
}
));
}
}
export class Todo {
constructor(
public id: number,
public description: string,
public status: boolean,
public date: Date
) {}
}
In console.log
I am able to see my JSON format with correct data from database. When I start angular application I do not have any errors in console but on my browser I can see only id numbers. Do not know what might be wrong in this case.
<div class="container">
<table class="table">
<thead>
<tr>
<th>Id</th>
<th>Target Date</th>
<th>is Completed?</th>
<th>Update</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let todo of todos">
<td>{{todo.description}}</td>
<td>{{todo.id}}</td>
<td>{{todo.status}}</td>
<td>{{todo.date}}</td>
</tr>
</tbody>
</table>
</div>
解决方案
You might have the incorrect property name, which is causing this issue.
推荐阅读
- android - 如何在android中查看与屏幕相关的活动/片段?
- python - 是什么让 python 中的 argv 有用?
- javascript - 使用 JavaScript 修剪 JSON 树
- php - 如何在 WooCommerce 中通过电子邮件发送购买的数字产品
- javascript - Axios.put ReactJS
- azure - 允许用户设置分支策略但不允许跨存储策略
- javascript - 如何使用 app.post 将 const 导出到另一个 const 之外?表达 Javascript
- javascript - 为什么我的代码特定部分的代码“backpack.unshift("Rock")" 在我的背包数组中没有 unshift()"Rock"?
- excel - Excel VBA - 创建记录表
- c++ - 仅当它不是别名时,如何编写 std::chrono::high_resolution 时钟类模板专业化