【发布时间】:2023-04-03 03:17:01
【问题描述】:
我编写了一个函数来检查我的 firebase 数据库的“phonenumber”子项中是否保存了数据.. 测试是好的!但是在这个函数里面我不能调用一个外部声明的变量! 这是代码:
phoneNumberExistence: boolean;
FIREBASE_DATABASE.ref("Settings").child('phoneNumber').once('value', function(snapshot) {
var exists = (snapshot.val() !== null);
//console.log("Phone number existance: "+exists);
if(exists){
this.phoneNumberExistence = true; //the problem is here.. can't use this variable
console.log("A phone number already exists.")
}
else{
this.phoneNumberExistence = false; //the problem is here.. can't use this variable
console.log("There is no phone number here :(");
}
})
有什么想法吗? 谢谢
【问题讨论】:
-
就个人而言,我从不在 Angular 中使用
this。坚持$scope。见stackoverflow.com/questions/11605917/…
标签: javascript angularjs typescript firebase firebase-realtime-database