Javascript Angular 2使用ngfor获取json数据

Javascript Angular 2使用ngfor获取json数据,javascript,angular,typescript,angular-http,Javascript,Angular,Typescript,Angular Http,我在URL中得到了一个JSON数组,我试图从中获取信息,以便在ngFor中使用它。如果我想获取链接或名称并在ngFor中使用它,我做错了什么?因为我在console.log(this.straip)中得到它,但不能在ngFor中使用它 组件。ts export interface straipsnelis { name: string; link: string; } straip = {} as straipsnelis; ngOnInit() { this.http.get('

我在URL中得到了一个JSON数组,我试图从中获取信息,以便在
ngFor
中使用它。如果我想获取链接或名称并在
ngFor
中使用它,我做错了什么?因为我在
console.log(this.straip)
中得到它,但不能在
ngFor
中使用它

组件。ts

export interface straipsnelis {
  name: string;
  link: string;
}

straip = {} as straipsnelis;
ngOnInit() {
  this.http.get('this.url').subscribe((data:any) => {
    this.straip.link = data.map((a:any)=>a.guid);
    this.straip.name = data.map((a:any)=>a.slug);
    console.log(this.straip);
  })
}
HTML

<div *ngFor="let s of straip" class="cardukas">
  <div class="left-photo">{{s.link}}</div>
  <div class="right-info"></div>
</div>

{{s.link}
控制台错误:

错误:找不到类型为“object”的不同支持对象“[object]”。NgFor只支持绑定到数组之类的可重用文件

ngFor不迭代对象,它只迭代数组

TS:

导出接口straipsnelis{
名称:字符串;
链接:字符串;
}
straip={}as straipsnelis;
straipArray:Array=[];
恩戈尼尼特(){
this.http.get('this.url').subscribe((数据:any)=>{
this.straip.link=data.map((a:any)=>a.guid);
this.straip.name=data.map((a:any)=>a.slug);
this.straipArray.push(this.straip)
console.log(this.straip);
})
}
HTML:


{{s.link}
ngFor不迭代对象,它只迭代数组

TS:

导出接口straipsnelis{
名称:字符串;
链接:字符串;
}
straip={}as straipsnelis;
straipArray:Array=[];
恩戈尼尼特(){
this.http.get('this.url').subscribe((数据:any)=>{
this.straip.link=data.map((a:any)=>a.guid);
this.straip.name=data.map((a:any)=>a.slug);
this.straipArray.push(this.straip)
console.log(this.straip);
})
}
HTML:


{{s.link}

plz提供控制台结果
straip
不是一个对象数组。如何将其转换为对象数组?{link:array(2),name:array(2)}link:array(2)0:{rendered:}1:{rendered:}length:2 proto:array(0)name:array(2)0:“h1 post name lorem ipsum dolor sit amet continuettetur adipsum adipsum dolor sas”1:“pirmasis tinklascio irascio”长度:2 proto:Array(0)proto:ObjectAngular无法循环对象,ngFor仅支持iterables,您需要提供一个数组。plz提供控制台结果
straip
不是对象数组。如何将其转换为对象数组?{link:Array(2),name:Array(2)}link:Array(2)0:{rendered:}1:{rendered:}长度:2 proto:Array(0)名称:数组(2)0:“h1 post name lorem ipsum dolor sit amet Concertetur adipiscing elit”1:“pirmasis tinklarascio irasas”长度:2 proto:Array(0)proto:ObjectAngular不能循环对象,NGO仅支持iterables,您需要提供一个数组。我得到了html格式的[Object Object],现在没有控制台错误。我得到了[Object]在html中。现在没有控制台错误。
export interface straipsnelis {
  name: string;
  link: string;
}

straip = {} as straipsnelis;

straipArray : Array<any> = []; 

ngOnInit() {
  this.http.get('this.url').subscribe((data:any) => {
    this.straip.link = data.map((a:any)=>a.guid);
    this.straip.name = data.map((a:any)=>a.slug);
    this.straipArray.push(this.straip)

    console.log(this.straip);
  })
}
<div *ngFor="let s of straipArray" class="cardukas">
  <div class="left-photo">{{s.link}}</div>
  <div class="right-info"></div>
</div>