【发布时间】:2018-06-03 04:00:57
【问题描述】:
我是 Angular5 的初学者,我需要你的帮助...
我在后端(Java/Spring Boot)中创建了一个 API,我可以使用 http://localhost:8080/applications 访问它
通过这个 API,我想检索一大块数据(它是一个 JSON 数组)。
我尝试在我的 Angular 上使用 httpClient 检索数据,但我的前端有这个结果:[object Object]
这是我的 app.component.ts
从“@angular/core”导入 {Component, Injectable}; 从“@angular/common/http”导入 {HttpClient, HttpErrorResponse}; 从“rxjs/Observable”导入 {Observable}; 导入'rxjs/add/operator/map'; @零件({ 选择器:'应用程序根', templateUrl: './app.component.html', styleUrls: ['./app.component.scss'] }) 导出类 AppComponent { url = 'http://localhost:8080/applications'; 水库= []; 构造函数(私有http:HttpClient){ } ngOnInit(): 无效 { this.http.get(this.url).subscribe(data => { this.res = 数据; 控制台.log(数据); }, (错误:HttpErrorResponse)=> { if (err.error instanceof Error) { console.log("发生客户端错误"); } 别的 { console.log("发生服务器端错误。"); } }); } }我的应用界面Application.ts
接口应用程序{ 身份证号码; 类型:字符串; 端口:字符串; baseUrl:字符串; 架构:字符串; 协议:字符串; 服务器:字符串; }如何显示我的数据?
提前致谢
【问题讨论】:
标签: json httpclient frontend display angular5