Доброго времени суток! Делаю небольшой проект на Angular 2. Споткнулся на простой вещи. Есть такой класс (app.data.ts):
export class Record {
public id_gng : number;
public kod3 :string;
public deleted : any;
}
export class DataResponse {
public data : Record[];
}
Я заполняю объект DataResponse данными из json в PHP-скрипте. Вот код app.service.ts
@Injectable()
class AppService {
constructor(private http:Http) {
}
public get(url:string) {
return this.http.get(url).toPromise();
}
public handleError(error:any) {
console.error('An error occurred', error);
return Promise.reject(error.message || error);
}
}
Никак не могу перебрать циклом экземпляр DataResponse. Вот код, который не могу заставить работать
export class AppComponent {
public result : DataResponse;
public setResponse(result:DataResponse) {
this.result = result;
}
constructor(private appService:AppService) {
this.result = new DataResponse();
this.appService.get('http://xxx/scripts/xxx.php')
.then(response => this.setResponse(response.json() as DataResponse))
.catch(this.appService.handleError);
for(let entry of this.result.data){
entry.id_gng = entry.id_gng + 1;
};
}
}
Как корректно осуществить цикл по this.result ? Вариант с for пробовал, выдает ошибку и все. Понимаю, что вопрос новичка. Спасибо.