I am retrieving a firebase collection using JavaScriptjaca and intend to get the difference between the current date and dates stored in the returned collection.
this.firebaseSrvc.function().subscribe((data)=>{
data.forEach(e =>{
const x = new Date(e.dataPagamento).toLocaleDateString();
const y = new Date().toLocaleDateString();
const a = Math.abs(new Date(y).valueOf() - new Date(x).valueOf());
const b = Math.ceil(a/(1000*60*60*24));
this.dates = b;
});
});
After that I want to populate an html table with "this.dates", but only appears the last item
<ion-grid>
<ion-row>
<ion-col id="b">{{dates}}</ion-col>
</ion-row>
</ion-grid>
I need help on how to fill the table with all this.dates values
>Solution :
Store the result in an array, not in a single number.
Try this:
this.firebaseSrvc.function().subscribe(
(data)=>{
this.dates = []; // <---- Create an empty array
data.forEach(e =>{
const x = new Date(e.dataPagamento).toLocaleDateString();
const y = new Date().toLocaleDateString();
const a = Math.abs(new Date(y).valueOf() - new Date(x).valueOf());
const b = Math.ceil(a/(1000*60*60*24));
this.dates.push(b); // <---- Push each result as a new entry in the array
});
});
Display the array using a for loop
For example, if you are using Ionic Vue:
<ion-grid>
<ion-row>
<ion-col v-for="date in dates">{{date}}</ion-col>
</ion-row>
</ion-grid>