[英]request running multiple times
我有這個 function,它調用谷歌社交登錄
loginnn($event){
this.socialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID);
this.socialAuthService.authState.subscribe((user) => {
this.frmLoginGoogle.patchValue({
email: user.email,
googleAuthToken: user.authToken,
});
console.log('loop after clicking again')
});
this.loginGoogle($event);
console.log('execute the function first than the one above')
}
問題是它在this.loginGoogle
之前運行this.socialAuthService
我已經嘗試將this.loginGoogle
放入訂閱中,但單擊幾下后它最終運行了好幾次
我認為這是正確的做法。
this.socialAuthService.signIn(GoogleLoginProvider.PROVIDER_ID).pipe(
switchMap(() => this.socialAuthService.authState), // switching from one to another observable after emit the value
tap((user) => {
this.frmLoginGoogle.patchValue({
email: user.email,
googleAuthToken: user.authToken,
});
this.loginGoogle($event);
}),
take(1) // limit the observable to complete after one time
).subscribe();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.