小编Ken*_*rok的帖子

显示Json数组Angular 5 HttpClient

我是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.");
            }
          });

      } …

frontend json httpclient display angular5

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular5 ×1

display ×1

frontend ×1

httpclient ×1

json ×1