在我单击UI之前,signInWithPopup Promise不会执行.catch. Angular和Firebase [英] signInWithPopup promise doesn't execute the .catch until I click the UI. Angular and Firebase
问题描述
我在AngularFireAuth提供的.signInWithPopup()方法上遇到麻烦,您可以在此处查看更多信息:
I'm having a trouble with the .signInWithPopup() method provided by AngularFireAuth, you can see more here: firebaseAuthReference
在我的auth.service.ts中,我使用以下方法.
In my auth.service.ts I've the following method.
signinWithFacebook2() {
const provider = new firebase.auth.FacebookAuthProvider();
return this.afAuth.auth.signInWithPopup(provider);
}
afAuth被注入到auth的构造函数中:
afAuth is been injected in the auth's constructor:
constructor(private router: Router,
private afAuth: AngularFireAuth){}
当用户单击我的login.component.ts中的按钮(单击事件)时,我调用signinWithFacebook2().
I call signinWithFacebook2() when the user click a button in my login.component.ts (click event).
onFacebookLogin() {
this.authService.signinWithFacebook2()
.then(
(res) => {
this.authService.getTokenId();
this.router.navigate(['/dashboard']);
}
)
.catch(
(err) => {
this.showError = true;
// TODO fix bug. this code isn't execute until I press the button again.
}
);
}
当诺言得以解决时,一切正常,代码将正确执行,但是当拒绝完成时,直到再次按下登录按钮,代码才执行.这是一种奇怪的行为.希望您了解我的问题,否则请发表评论.
When the promise is resolved everything is OK, the code is executed correctly but when the reject is been accomplished the code isn't executed until I press the login button again. This is a strange behavior.Hope you have understanded my problem, if not please leve a comment.
推荐答案
尝试强制更改检测错误.
-
添加导入:
add import:
import { ChangeDetectorRef } from '@angular/core';
传递对构造函数的引用:
pass reference to constructor:
constructor(private router: Router,
private ref: ChangeDetectorRef,
private afAuth: AngularFireAuth) {}
强制更改错误检测:
force change detection on error:
(err) => {
this.showError = true;
// TODO fix bug. this code isn't execute until I press the button again.
this.ref.detectChanges();
)
这篇关于在我单击UI之前,signInWithPopup Promise不会执行.catch. Angular和Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!