Я пытаюсь отобразить данные в моем приложении Angular 8
. Мой веб-сервис возвращает следующее json:
{
"content": [
{
"id": 1,
"name": "test name",
"email": "test@test.com",
"img_url": "url",
"field1": [
{
"id": 10,
"userId": 1,
"registeredAt": "2020-01-09T22:21:23.272",
"amount": 200
}
],
"field2": [
{
"id": 11,
"userId": 1,
"registeredAt": "2020-01-09T22:21:46.113",
"amount": 200
}
],
"creationDateTime": "2020-01-05T00:00:00Z"
}
],
"page": 0,
"size": 30,
"totalElements": 1,
"totalPages": 1,
"last": true
}
И для каждого элемента этого массива я хочу отобразить div с картой стиля, например:
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="url" alt="test name">
<div class="card-body">
<p class="card-text">test@test.com</p>
</div>
</div>
Код выше I введите app.component.ts
.
Я начал с модификации моего app.component.ts
и ввел туда:
export class AppComponent implements OnInit {
title = 'myTestfrontend';
mystructure: MyStructure[] = [];
constructor(private api: ApiService) {}
ngOnInit() {
this.getMyStructure();
}
getMyStructure() {
this.api.getMyStructure()
.subscribe(resp => {
for (const content of resp.body) {
this.mystructure.push(content);
}
});
}
}
, но он возвращает ошибку:
undefined is not a function (near '...content of resp.body...')
Что здесь не так, и как я могу это исправить, чтобы я мог отобразить столько карт, сколько есть записей в моем json? Большое спасибо!