I'm encountering a problem trying to display JSON data in a list format. It seems like something is missing because the data isn't showing up. Below is the code I've been using:
Service:
getData() {
this.http.post('http://localhost/api/Acc/GetData', "").subscribe(res => {
return res;
});
}
Component:
constructor(private api: ApiService) {
var data = api.getData();
}
Template:
<mat-list>
<mat-list-item *ngFor="let item of data">
<h4 matLine> {{item.Field1}} </h4>
</mat-list-item>
</mat-list>
Upon inspection, I can identify some areas that may be causing issues:
I am uncertain if
getData
is correctly returning the data.I am unsure if the constructor is effectively storing the data. I have tried alternative methods but none seem to work.