I am new in Angular 2 and I want to display all the API data in tabular form. Here is my working code:
http://plnkr.co/edit/CB3oGppm4fvoEExfDSRc?p=preview
But when I am using this code in my files, I am having 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)
);
}
}
This code is working in Plunkr but having error when I try it in my project. Please help to iterate the API values in my project. Thank you.