我正在使用Ionic 3 / Angular 4 / Firebase构建应用程序。以下代码正确验证用户身份,登录正常。
但我无法阅读error.code
,即使它位于console.log(error)
。
这是我的代码:
firebase.auth().signInWithEmailAndPassword(this.user.email, this.user.password)
.then((result) => {
// show toast
this.toast.show("Login was successful");
// set user to storage
this.storage.set("user", JSON.stringify(result))
// restore form submitted state
this.submitted = false;
// set nav root to Dashboard
this.navCtrl.setRoot("DashboardPage");
})
.catch((error) => {
console.error(error);
let errorCode = error.code // THIS CAN'T BE READ
});
VS代码建议的错误对象的属性为error.message
,error.name
和error.stack
。
这是控制台日志:
O {code: "auth/invalid-email", message: "The email address is badly
formatted."}
code: "auth/invalid-email"
message: "The email address is badly formatted."
更新
投射到any
有效,但我不认为这是应该做的。
.catch((error: any) => {