Javascript DefaultIterableDiffer.diff仅允许使用数组和iterables

Javascript DefaultIterableDiffer.diff仅允许使用数组和iterables,javascript,angular,typescript,angular-cli,Javascript,Angular,Typescript,Angular Cli,我试图从api中获取数据,以显示在Angular上的component.html上。但我被这个问题困住了 所以它应该显示API中的死亡总数,即“238569” 错误:尝试区分“238569”时出错。只允许使用数组和iterables component.html <li *ngFor="let deaths of tDeaths" [value]="deaths"> {{ deaths }} </li> 服务台 import { Injectable } fro

我试图从api中获取数据,以显示在Angular上的component.html上。但我被这个问题困住了

所以它应该显示API中的死亡总数,即“238569”

错误:尝试区分“238569”时出错。只允许使用数组和iterables

component.html

<li *ngFor="let deaths of tDeaths"
  [value]="deaths">
  {{ deaths }}
</li>
服务台

import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';



@Injectable({
  providedIn: 'root'
})
export class CoronaService {

  constructor(private http: HttpClient) {
    this.getJSON().subscribe(data => {
    });
}

public getJSON(): Observable<any> {
    return this.http.get("https://api.covid19api.com/summary");
}
}
从'@angular/core'导入{Injectable};
从'@angular/common/http'导入{HttpClient};
从“rxjs”导入{Observable};
@注射的({
providedIn:'根'
})
出口级服务{
构造函数(专用http:HttpClient){
this.getJSON().subscribe(数据=>{
});
}
public getJSON():可观察{
返回此.http.get(“https://api.covid19api.com/summary");
}
}

似乎您正在尝试迭代一个数字。您需要向*ngFor提供一个数组(可能要将一个对象映射到一个带有object.keys/object.values的数组),或者如果输出值本来不应该是数组,就不要使用ngFor。

似乎您正在尝试迭代一个数字。您需要向*ngFor提供一个数组(可能要将一个对象映射到一个带有object.keys/object.values的数组),或者如果输出值本来不应该是数组,则不使用ngFor。

您需要将数据推送到OnInit中的TDeath。因为您将它声明为数组。
ngOnInit():void{
this.coronalservice.getJSON().subscribe(数据=>{
控制台日志(数据);
this.tDeaths.push(data.Global.TotalDeaths);
返回此.tDeaths
});

}
您需要将数据推送到OnInit中的TDeath。因为您将它声明为数组。
ngOnInit():void{
this.coronalservice.getJSON().subscribe(数据=>{
控制台日志(数据);
this.tDeaths.push(data.Global.TotalDeaths);
返回此.tDeaths
});
}
我检查了处的数据,似乎您试图从数字中呈现列表,这毫无意义,因此您可能只想将数字呈现为单个元素,如{{tDeaths}}我检查了处的数据,似乎您试图从数字中呈现列表,这毫无意义,因此,也许您只想将数字呈现为单个元素,如{{tDeaths}}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';



@Injectable({
  providedIn: 'root'
})
export class CoronaService {

  constructor(private http: HttpClient) {
    this.getJSON().subscribe(data => {
    });
}

public getJSON(): Observable<any> {
    return this.http.get("https://api.covid19api.com/summary");
}
}