async incrementTuts(key) {
let newData= {'tutsApplied':this.tutsApplied+1}
let newInfo = firebase.database().ref('thisis/'+this.route.snapshot.paramMap.get('key')).update(newData);
}
I want to increment tutsApplied on firebase realtime database using ionic 4. how can i acheive that.
Corrected image:
update:
i have used
let key = this.route.snapshot.paramMap.get('key');
let ref = firebase.database().ref(`thisis/${key}/tutsApplied`);
ref.transaction((current) => {
return (current || 0) + 1;
});
but new field is created under undefined as shown in image. i dont want to create new field. and how can i print current value in console?
It sounds like you're looking to write a new value for a property based on its current value. To do that, you'd use a transaction .
Something like:
let key = this.route.snapshot.paramMap.get('key');
let ref = firebase.database().ref(`thisis/${key}/tutsApplied`);
ref.transaction((current) => {
return (current || 0) + 1;
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.