Reputation: 1
I am trying to update data on firebase realtime database using angular and angularFire, the data changes but after few seconds it goes back to original data this is the function I am using.
onSaveDateUpdate(){
let temp = {
period:{
startDate:'',
endDate:'',
periodType:''
},
updatedTime:("0" +(this.r.getMonth()+1)).slice(-2)+"/"+("0" +this.r.getDate()).slice(-2)+"/"+this.r.getFullYear()+" "+this.r.getHours()+":"+this.r.getMinutes()+":"+this.r.getSeconds()
};
var save =this.onEndDateValidator();
if(save){
temp.period.startDate = this.datePipe.transform(this.editStartDate,'MM/dd/yyyy');
temp.period.endDate = this.datePipe.transform(this.editEndDate,'MM/dd/yyyy');
temp.period.periodType = this.periodType;
const itemRef = this.db.object(URL );
this.showDateEdit = !this.showDateEdit;
itemRef.update(temp).then(() => {
...
});
}
Upvotes: 0
Views: 380
Reputation: 598817
This behavior typically means that you have security rules that reject the write operation.
When you perform a write operation in the app, the Firebase client initially assumes that the write will success, and fires local events right away. This is one of the reasons why UI updates happen so fast when you use Firebase.
On the server, the database checks the write operation against your security rules. If the user is authorized, the write is allowed, otherwise it is rejected. In either of these cases, the server informs the client of the result. And in the case of a rejected write, the client then makes sure the local state gets updated to reflect the server state. That reverting of the local state sounds like what you're seeing, and the delay makes sense if it's due to the client-server distance/latency.
Upvotes: 1