Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ionic framework 把两个数相加_Ionic Framework_Ionic5 - Fatal编程技术网

Ionic framework 把两个数相加

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

我正在尝试添加来自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().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]