I got a JSON array in URL and I am trying to get information from it so I could use it in ngFor
. What am I doing wrong if I want to get link or name and use it in ngFor
? Because I get it in console.log(this.straip)
, but cannot use it in ngFor
.
Component.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>
Console error:
ERROR Error: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.