Angular 找不到不同的支持对象角度7

Angular 找不到不同的支持对象角度7,angular,angular7,Angular,Angular7,嗨,我用的是Angular 7 我创建了service user-report.service.ts for get方法未在浏览器中打印 getReport() { /*this.http.get(`${this.apiUrl}/report`) .subscribe(res => console.log(res._body));*/ return this .http .get(`${th

嗨,我用的是Angular 7

我创建了service user-report.service.ts for get方法未在浏览器中打印

getReport() {
        /*this.http.get(`${this.apiUrl}/report`)
            .subscribe(res => console.log(res._body));*/
        return this
           .http
           .get(`${this.apiUrl}/report`);
    }
用户报告.component.ts

getReport() {
        this.userReport.getReport()
            .subscribe((data: UserReport[]) => {
            this.reports = data;
            console.log(data);
    });
    }
模板

<table class="table table-hover">
  <thead>
  <tr>
      <td>User Name</td>
      <td>Created Date</td>
      <td>Updated Date</td>
      <td>Time</td>
      <td>Status</td>
  </tr>
  </thead>

  <tbody>
      <tr *ngFor="let report of reports">
          <td>{{ report.username }}</td>
          <td>{{ report.created_date }}</td>
          <td>{{ report.updated_date }}</td>
          <td>{{ report.time }}</td>
          <td>{{ report.status }}</td>

      </tr>
  </tbody>
</table>

用户名
创建日期
更新日期
时间
地位
{{report.username}
{{report.created_date}
{{report.updated_date}
{{report.time}
{{report.status}
但我犯了这样的错误

错误:找不到不同的支持对象响应,URL:'类型为'object',状态为:200 OK。NgFor仅支持绑定到阵列之类的iTerable。


我不知道问题出在哪里

将单个报表转换为数组的简单修复方法:

getReport() {
        this.userReport.getReport()
            .subscribe((data: UserReport) => {
            this.reports = [data];
            console.log(data);
    });
    }

检查此.userReport.getReport()…它没有返回数组-它是否返回单个报告?。尝试在浏览器中测试URL。仅供参考,仅仅因为您将对象强制转换为数组,就不会这样。NgFor仅支持绑定到数组等可重用项。您在数据中收到了什么?它是数组还是对象?我的数据响应{headers:headers{{headers:Map(1),{u normalizedNames:Map(1)}ok:true status:200 statusText:“ok”类型:2 url:“localhost:3000/report”{u body:[{u id:“5BEC00C1043E8B080858E36”,“用户名:“名称”,“创建日期”:“2018年11月14”,“更新日期”:“2018年11月14”,“时间”:“下午4:32”,“状态”:“D”,“v:”0},]_uuproto:Body}this.reports=[data._Body];它工作正常,但在表中,注释被打印出来。为什么数据?您在json中返回的属性是否为body?标题:标题{uHeaders:Map(1),normalizedNames:Map(1)}确定:真实状态:200状态文本:“确定”类型:2 url:body:[{uID:“5BEC00C1043E8B080858E36”,“用户名”:“名称”,“创建日期”:“2018年11月14”,“更新日期”:“2018年11月14”,“时间”:“下午4:32”,“状态”:“D”,“v”:0},]”__proto:body查看您的json,_body已经是一个数组了。尝试
this.reports=data._body
;我认为如果我打印这个{{reports}}它打印出来但不工作,循环是个问题