I have been attempting to iterate through my array of data, but I am not receiving any error messages or feedback at all.
When I try to iterate through an object, I encounter the following error message, but the elements are still being created:
Error: NG02200: Cannot find a differ supporting object '[object Object]' of type 'object'.
To fix this error, I am trying to push the individual objects into an array.
export interface iProjectNewsData {
id: number;
....
}
export class ProjectNewsComponent implements OnInit {
top3News: iProjectNewsData[] = [];
constructor(
....
private projectNewsService: ProjectNewsService
) {
this.projectNewsService.fetchTop3News().subscribe((data: any) => {
data.forEach((item: iProjectNewsData) => {
this.top3News.push(item);
});
});
}
Now, I believe the problem is that the objects are being pushed into array index 0. Why is it not incrementing the index?
[]
0: {id: 1, …}
1: {id: 2, …}
2: {id: 3, …}
length: 3
[[Prototype]]: Array(0)
The HTML section:
<ng-container>
<div *ngFor="let news of top3News" [ngModel]="top3News" name="Top3NewsElement" ngDefaultControl>
<img src="/assets/images/project-news/{{ news.image }}" class="w-full h-full rounded-top">
</div>
</ng-container>