在离子中添加两个数字
Adding two number in Ionic
我正在尝试添加一个来自我的 firebase 实时数据库的数字和另一个来自 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')
}
})
})
但是结果显示“050505050505050”我已经尝试使用 ParseInt() 但它不起作用。
我认为你需要像下面这样在 sum 之前转换 this.data.point。
point: +this.data.point + this.number
我正在尝试添加一个来自我的 firebase 实时数据库的数字和另一个来自 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')
}
})
})
但是结果显示“050505050505050”我已经尝试使用 ParseInt() 但它不起作用。
我认为你需要像下面这样在 sum 之前转换 this.data.point。
point: +this.data.point + this.number