Using TypeScript in CompanyComponent Class
export class CompanyComponent {
apiService : APIService;
data : any;
private companyUrl = 'http://localhost:4000/api/company/';
constructor(apiService : APIService) {
this.apiService = apiService;
this.retrieveCompanies(this.companyUrl);
}
retrieveCompanies(url: any){
this.data = this.apiService.GET(url).map((response :Response)=>
response.json()).subscribe((response)=>{
this.data = response;
console.log(this.data);
})
}
Array Response from Server
[
{"_id":"58f61a132d44240d085ca2fa","comapny_name":"Burslem
Spice","__v":1,"categories":["58f643382d44240d085ca2fb"]},<br>
{"_id":"590487964a45c56c0fa2911a","comapny_name":"Tiger
Bite","categories":[]}
]
HTML Template for Displaying Data
<div class="media">
<div class="media-left" >
<li class="media" *ngFor = "let comp of data" >
<label>{{comp}}</label>
</li>
</div>
</div>
The server's response is an array, but I am encountering the following error:
ERROR caused by: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.