This keeps kicking upError: Cannot find a differ supporting object ‘[object Object]’ of type ‘object’. NgFor only supports binding to Iterables such as Arrays. But it works when I try print it to the console, any help be appreciated big time guys
Thank you (:
JavaScript
x
9
1
//TypeScript File :
2
public names = ["Jimmy" , "Lilly"];
3
public ages = [20,25];
4
public profile = {
5
Name : this.names,
6
Age : this.ages
7
}
8
9
JavaScript
1
6
1
//HTML File :
2
<div *ngFor = "let i of profile">
3
{{i.Name}}
4
{{i.Age}}
5
</div>
6
Advertisement
Answer
The error already mentions what’s the issue.
NgFor only supports binding to Iterables such as Arrays
You need to use an array in order that *ngFor
works
JavaScript
1
5
1
//TypeScript File
2
public jimmy = { Name: "Jimmy", Age: 20 };
3
public lilly = { Name: "Lilly", Age: 25 };
4
public profiles = [jimmy, lilly]
5
JavaScript
1
6
1
//HTML File :
2
<div *ngFor = "let i of profiles">
3
{{i.Name}}
4
{{i.Age}}
5
</div>
6