【发布时间】:2020-06-08 00:21:40
【问题描述】:
我在后台使用 Ionic 和 Angular。
设置
"@angular/router": "~9.1.9",
"@ionic/angular": "^5.1.1",
"rxjs": "^6.5.5",
我使用以下登录方法:触发时显示微调器,加载数据,路由到另一个页面,然后再次隐藏微调器。
loginWithGoogle() {
this.showSpinner = true;
this.authService.getAuthSessionPersistence()
.pipe(
concatMap(() => this.authService.getAuth().signInWithPopup(new auth.GoogleAuthProvider())),
concatMap(() => this.databaseService.getUserModel()
.pipe(
concatMap(userModel => {
if (Object.keys(new UserInit()).every(key => userModel[key])) {
return of(userModel).pipe(first());
}
return this.authService.getUser()
.pipe(
concatMap(user => this.databaseService.createUser(user.uid, userModel))
);
}),
concatMap(userModel => this.store.dispatch([
new SaveUserAction(userModel),
new LoadFixturesAction(),
new LoadTeamsAction(),
new LoadTransactionsAction(),
])
),
tap(() => this.router.navigateByUrl('tabs/home'))
)),
finalize(() => this.showSpinner = false)
)
.subscribe();
}
问题是微调器在路由发生之前就被隐藏了。用户会再次看到不太友好的登录屏幕。
正如您在上面的代码中看到的:最后一个 RxJS 运算符是使用 finalize,这是微调器被隐藏的地方。
你知道为什么路由器导航需要很长时间吗?
【问题讨论】:
-
那么如果将“finalize”移动到“tap”之后的位置会发生什么?
-
@SergeyRudenko 效果一样
标签: angular rxjs angular-routing