Hello, I am trying to add a number from firebase realtime database and another number using angular.
check(){
firebase.database().ref('users/').once('value', (snapshot) => {
snapshot.forEach(snap => {
this.newlist.push(snap.val().referralCode);
if(this.checking.referralCode == snap.val().referralCode){
console.log('Referral Code Exists')
this.presentAlert();
this.auth.onAuthStateChanged(se => {
this.fire = firebase.database().ref('users/' + se.uid).on('value', resp => {
this.data = resp.val()
let point = Number(this.data.point) || this.data.point;
console.log(point)
this.number = parseInt('50')
this.afDB.object('users/'+ se.uid).update({
point: point + parseInt('50'),
})
console.log(resp)
})
})
return true;
}
else{
console.log('Invalid')
}
})
})
}
The result I got was 69000, the part where the numbers add together works however it runs in a loops hence the big number. is there a way i can prevent a loop from happening?