Ionic framework 把两个数相加
我正在尝试添加来自firebase实时数据库的一个数字和来自ionic的另一个数字Ionic framework 把两个数相加,ionic-framework,ionic5,Ionic Framework,Ionic5,我正在尝试添加来自firebase实时数据库的一个数字和来自ionic的另一个数字 ngOnInit(){ this.number=[50] } 检查(){ firebase.database().ref('users/')。once('value',(快照)=>{ snapshot.forEach(snap=>{ this.newlist.push(snap.val().referralCode); if(this.checking.referralCode==snap.val().refe
ngOnInit(){
this.number=[50]
}
检查(){
firebase.database().ref('users/')。once('value',(快照)=>{
snapshot.forEach(snap=>{
this.newlist.push(snap.val().referralCode);
if(this.checking.referralCode==snap.val().referralCode){
console.log('存在引用代码')
这个.presentAlert();
this.auth.onAuthStateChanged(se=>{
this.fire=firebase.database().ref('users/'+se.uid).on('value',resp=>{
this.afDB.object('users/'+se.uid).update({
点:parseInt(this.data.point+this.number),
})
控制台日志(resp)
})
})
返回true;
}
否则{
console.log('无效')
}
})
})
我认为你需要在求和之前先计算这个.data.point,如下所示
point: +this.data.point + this.number
我得到一个错误运算符“+”不能应用于类型“number”和“number[]”。当我在前面加上+时that@JoyCheng为什么你的
this.number=[50]
是一个数组吗?如果你想要一个简单的数字,你应该将它改为:this.number=50
@JoyCheng如果你不想用数字替换你的数组,你可以写:+this.data.point+this.number[0]