As a beginner in Ionic/Angular, I am attempting to fetch data from a JSON file and display it using cards in the HTML.
The JSON contains numerous objects that are either marked as "deTurno == true" or "deTurno == false".
Here is what I have so far:
public data: any;
public test: any;
public testTwo: any;
constructor(private apiService: ApiService) {
this.apiService.getFarmacias().subscribe(
(data) => {
this.data = data;
for (const item of this.data) {
if (item.deTurno == true) {
// copy the item inside this.test
} else {
// copy the item inside this.testTwo
}
}
}
);
}
My goal is to extract all items from the JSON that match "deTurno == true", store them in 'test', and then use 'test' to display those items in the HTML like this:
<ion-card *ngFor="let dataItem of test">
<ion-card-header>
<ion-card-subtitle>{{dataItem.direccion}}</ion-card-subtitle>
<ion-card-title>{{dataItem.nombre}} (De turno hoy)</ion-card-title>
<h5>Localidad: {{dataItem.localidad}}</h5>
<h4>{{dataItem.telefono1}}</h4>
</ion-card-header>
</ion-card>
I only want to display items that match "deTurno == true" while doing something with the items that match "deTurno == false". Otherwise, I would be showing every item from 'data'.
Please provide assistance :(