我是Angular5的初学者,我需要你的帮助......
我在我的后端(Java/Spring Boot)中创建了一个API,我可以访问它 http://localhost:8080/applications
使用此API,我想检索一大块数据(它是一个JSON数组).
我尝试在我的Angular上使用httpClient检索数据,但我在前端有这个结果:[object Object]
这是我的app.component.ts
import {Component, Injectable} from '@angular/core';
import {HttpClient, HttpErrorResponse} from "@angular/common/http";
import {Observable} from "rxjs/Observable";
import 'rxjs/add/operator/map';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
url = 'http://localhost:8080/applications';
res = [];
constructor(private http: HttpClient) {
}
ngOnInit(): void {
this.http.get(this.url).subscribe(data => {
this.res = data;
console.log(data);
},
(err: HttpErrorResponse) => {
if (err.error instanceof Error) {
console.log("Client-side error occured.");
} else {
console.log("Server-side error occured.");
}
});
} …