I'm a beginner in Angular 2 and I am looking to present all the API data in a tabular format. Below is the code that is currently working for me:
http://plnkr.co/edit/CB3oGppm4fvoEExfDSRc?p=preview
However, when I implement this code in my files, I encounter an error:
Type 'Response' is not assignable to type 'any[]'
test.component.html:
<h1>{{getData[0]?.name}}</h1>
<h1>{{getData[0]?.time}}</h1>
<div *ngFor="let item of getData">
<span>{{item?.name}}</span>
</div>
app.component.ts
import { Component } from '@angular/core';
import { ConfigurationService } from './ConfigurationService';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent {
getData = [];
constructor(private _ConfigurationService: ConfigurationService)
{
console.log("Reading _ConfigurationService ");
//console.log(_ConfigurationService.getConfiguration());
this._ConfigurationService.getConfiguration()
.subscribe(
(data)=> {
this.getData = data;
console.log(this.getData);
},
(error) => console.log("error : " + error)
);
}
}
The code functions correctly in Plunkr, but I am encountering errors when trying it in my own project. Any assistance on how to iterate through the API values in my project would be greatly appreciated. Thank you.