【发布时间】:2018-03-18 01:24:45
【问题描述】:
我有一个用于创建新的 firebase 用户的打字稿功能。 我想在函数之外获取用户对象(由该函数创建),但是当我尝试 console.log 时,我在控制台中得到“未定义”。
async saveProfile(){
const secondaryApp = this.firebase.initializeApp(this.config,"appname2");
var X;
try {
secondaryApp.auth().createUserWithEmailAndPassword(this.em, this.pwd)
.then(function test(firebaseUser) {
X = firebaseUser;
//Here I CAN GET THE OBJECT X
console.log(X);
secondaryApp.auth().signOut();
})
//I WANT TO GET THE X OBJECT HERE !!
//BUT I GET "UNDEFINED"
console.log(X);
}
catch(e){
console.error(e);
this.toast.create({
message: e.message,
duration: 3000
}).present();
}
}
对不起,如果这个问题有点愚蠢,但我是初学者,尤其是使用打字稿。谢谢:)
【问题讨论】:
标签: typescript