【发布时间】:2018-01-07 07:34:22
【问题描述】:
我正在使用 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 Code 建议的错误对象的属性为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) => {
【问题讨论】:
标签: angular firebase ionic-framework firebase-authentication