Please note that other questions about the same error didn't help because I'm using different way to get the data.
I want to get some data from the API and show them in the page using Angular
.
The http request will get an array of projects.
so here is the projects.component.ts
:
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
interface Project {
alias:Array<string>;
apps:Array<string>;
description: string;
id:string;
name:string;
}
@Component({
selector: 'app-projects',
templateUrl: './projects.component.html',
styleUrls: ['./projects.component.css']
})
export class ProjectsComponent {
title:string = "Projects";
dataProjects: Array<Project>;
constructor(private httpClient:HttpClient){ }
getProjects() {
this.httpClient.get<Array<Project>>("http://company.com/v1/api/projects")
.subscribe( data => { this.dataProjects = data; } )
}
}
and here is the view in projects.component.html:
<tbody>
<tr *ngFor="let proj of dataProjects">
<td> {{ proj.name }} </td>
<td>{{ proj.description }} </td>
</tr>
</tbody>
This is the error I get:
Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.
How to return an array of Projects ?
EDIT:
Example of output of the API:
{
"results": [
{
"alias": [
"project"
],
"apps": [],
"description": "Applications natives",
"id": "project",
"name": "project"
}
]
}
http://company.com/v1/api/projects
? – Vivek Doshi