недавно создав проект TNS с tns create myApp --ng и требует httpModule, как описано в документации -> я просто получаю свои данные из JSON моего удаленного Сервера.
НО:
По какой-то причине первым элементом возвращаемого массива является следующий объект, который впоследствии выдает ошибки:
JS: ==== object dump start ====
JS: 0: {
JS: "__zone_symbol__state": null,
JS: "__zone_symbol__value": []
JS: }
JS: 1: {
JS: "id": 1,
и т. Д.
Мой сервис выглядит следующим образом (item.service.ts):
import { Injectable } from "@angular/core";
import { Item } from "./item";
const httpModule = require("http");
@Injectable()
export class ItemService {
private items = new Array<Item>(
httpModule.request({
url: "https://www.example.com/data.json",
method: "GET"
}).then((response) => {
var obj = response.content.toJSON();
for (let i=0; i<obj.length; i++) {
//console.log(obj[i]);
this.items.push(new Item(obj[i].id, obj[i].name, obj[i].role, obj[i].vereine, obj[i].testAufgaben));
//console.log("items object testaufgaben: "+this.items[i].testAufgaben)
console.dir(this.items);
}
//console.log(obj);
}, (e) => {
console.log(e);
})
);
getItems(): Item[] {
return this.items;
}
getItem(id: number): Item {
return this.items.filter(item => item.id === id)[0];
}
}
Моя импортированная модель выглядит следующим образом (item.ts):
export class Slot {
constructor(
public slot: string,
public fillIn: boolean
) {}
}
export class Aufgabe {
constructor(
public aufgabe: string,
public aufgabeSlots: Array<Slot>
) {}
}
export class Item {
constructor(
public id: number,
public name: string,
public role: string,
public vereine: Array<string>,
public testAufgaben: Array<Aufgabe>
) {}
}
Любой, у кого есть хорошая идеячто это за сообщение об ошибке и что я могу сделать, чтобы избежать его?
Заранее большое спасибо.