Authentication Angularfire2电子邮件身份验证引用承诺之外的变量
我有这个部分:Authentication Angularfire2电子邮件身份验证引用承诺之外的变量,authentication,typescript,angular,promise,angularfire,Authentication,Typescript,Angular,Promise,Angularfire,我有这个部分: 导出类登录组件{ 登录_错误=”; 建造商(公共af:AngularFire){ this.af.auth.subscribe(auth=>console.log(auth)); } 登录(凭证){ this.af.auth.login({email:credentials.email,password:credentials.password}) .catch(函数(错误){ 开关(错误代码){ 案例“无效用户”: console.log(“无效电子邮件”); this.lo
导出类登录组件{
登录_错误=”;
建造商(公共af:AngularFire){
this.af.auth.subscribe(auth=>console.log(auth));
}
登录(凭证){
this.af.auth.login({email:credentials.email,password:credentials.password})
.catch(函数(错误){
开关(错误代码){
案例“无效用户”:
console.log(“无效电子邮件”);
this.login\u error=“电子邮件无效”//我将使用箭头函数。因此,您可以使用上下文this
(此处的组件实例):
登录(凭证){
this.af.auth.login({email:credentials.email,password:credentials.password})
.catch((error)=>{//当我看到这个解决方案是多么简单时,我笑了。这确实有效。我肯定还有更多关于ES6和JS的知识要学习。谢谢你,蒂埃里!
login(credentials) {
this.af.auth.login({ email: credentials.email, password: credentials.password})
.catch((error) => { // <-------
switch (error.code) {
case "INVALID_USER":
console.log("Invalid email");
this.login_error = "Email is invalid";
break;
case "INVALID_PASSWORD":
console.log("Invalid password");
this.login_error = "Password is invalid";
break;
default:
break;
}
});
}