私はAngular 2で新しく、すべてのAPIデータを表形式で表示したいと思います。ここで が私の作業コードです:Angular 2でngForを使用してAPIデータを反復する方法
http://plnkr.co/edit/CB3oGppm4fvoEExfDSRc?p=preview
しかし、私は私のファイルにこのコードを使用しています、私はエラーが生じています:
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)
);
}
}
このコードはPlunkrで動作していますが、プロジェクトで試してみるとエラーが発生します。私のプロジェクトでAPI値を繰り返すのを助けてください。ありがとうございました。
このエラーが発生している場所でコード行を共有できますか?プランナーではなくあなたのコード内にあります。 – echonax
レスポンスの配列が得られない可能性があるため、レスポンスとチェックフォーマットを出力します。応答オブジェクト内に[]があります。 – Sreemat
@echonaxモジュールビルドに失敗しました:エラー:app.component.ts(20,17) 'は' any [] '型に割り当てられません。 – vinayofficial