Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Authentication Angularfire2电子邮件身份验证引用承诺之外的变量_Authentication_Typescript_Angular_Promise_Angularfire - Fatal编程技术网

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;   
    }
  });
}