Search code examples
ionic-frameworkionic5

Adding two number in Ionic


i am trying to add a number from my firebase realtime database and another number from ionic.

ngOnInit() {
    this.number = [50]
  }
  
  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.afDB.object('users/'+ se.uid).update({
                  point: parseInt(this.data.point + this.number),
                  
                })
                
              console.log(resp)
              })
            
            }) 
            
            return true;
            
          }
          else{
          console.log('Invalid')
          }
          
         

      })
     
    })

However the result showed '050505050505050' I have tried using ParseInt() but that does not work.


Solution

  • I think you need to cast this.data.point before sum like below.

    point: +this.data.point + this.number