Я пытаюсь загрузить json через http-клиент, но когда дело доходит до представления, я всегда получаю эту ошибку:
NgFor only supports binding to Iterables such as Arrays
Когда я смотрю на вывод console.log, я вижу, что это объект с другими объектами в нем.
Это мой сервисный код:
@Injectable()
export class DataService {
data: any;
constructor(private http: Http) {
this.data = null;
}
load() {
// We're using Angular Http provider to request the data,
// then on the response it'll map the JSON data to a parsed JS object.
// Next we process the data and resolve the promise with the new data.
return this.http.get('http://localhost:3000/db') //json url
.map(res => res);
}
}
Затем мой конструктор page.ts, в который загружаются данные:
constructor(private nav:NavController, navParams:NavParams, http:Http, public service:DataService) {
this.service.load().subscribe (
response => {
this.displayData=response;
console.log(this.displayData);
},
error => console.log ('error in download')
);
}
Моя страница page.html ngfor:
<ion-card *ngFor="let data of displayData">
</ion-card>
И, наконец, мой json из URL-адреса localhost:
{
"0": {
"title": "Erreichbarkeit",
"items": [
{
"name": "1",
"value": "a"
},
{
"name": "2",
"value": "b"
},
{
"name": "3",
"value": "c"
}
]
},
"1": {
"title": "Erreichbarkeit 2",
"items": [
{
"name": "1",
"value": "g"
},
{
"name": "2",
"value": "f"
},
{
"name": "3",
"value": "e"
}
]
}
}
Надеюсь, кто-нибудь знает, что не так, потому что это сводит меня с ума.
[{"title" : ...}, {"title": ...}]
, потому что сейчас это неarray
, аobject
с двумяproperties
с именами 0 и 1 - person sebaferreras   schedule 12.07.2016