I encountered an issue while trying to update Firebase from Ionic. Below is the function I used to update the data.
Below is the TypeScript code:
updateLaporan()
{
this.id = this.fire.auth.currentUser.uid;
this.db.list('/laporan/'+this.id).update({
mydate : this.mydate.value,
porsiKarbohidrat : this.porsiKarbohidrat.value,
porsiProteinHewani : this.porsiProteinHewani.value,
porsiProteinNabati : this.porsiProteinNabati.value,
porsiLemak : this.porsiLemak.value,
})
this.alert("Data updated successfully")
}
This is the HTML for editing the data, where I attempted to pass and receive the values in TypeScript using ViewChild:
<ion-content padding>
<ion-list>
<ion-datetime displayFormat="MMM DD YY" [(ngModel)]="myDate" #mydate></ion-datetime>
<ion-item>
<ion-label floating>Porsi Karbohidrat</ion-label>
<ion-input type="number" #porsiKarbohidrat></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Porsi Protein Hewani</ion-label>
<ion-input type="number" #porsiProteinHewani></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Porsi Protein Nabati</ion-label>
<ion-input type="number" #porsiProteinNabati></ion-input>
</ion-item>
<ion-item>
<ion-label floating>Porsi Lemak</ion-label>
<ion-input type="number" #porsiLemak></ion-input>
</ion-item>
</ion-list>
<button ion-button full (click)="updateLaporan()">Update</button>