我有这样的身份验证服务
authState$: BehaviorSubject < any > ;
constructor(
private af: AngularFireAuth,
private db: AngularFirestore,
public router: Router) {
this.authState$ = new BehaviorSubject < any > ({});
}
doMicorosftLogin() {
this.authState$.next(Object.assign({}, {
uid: null,
loading: true
}));
const provider = new
auth.OAuthProvider('microsoft.com').setCustomParameters({
tenant: 'aaa-bbb-ccc-ddd'
});
this.af.auth
.setPersistence(auth.Auth.Persistence.LOCAL).then(() => {
this.af.auth.signInWithPopup(provider)
.then(res => {
this.authState$.next(Object.assign({}, {
uid: res.user.uid,
loading: false
}));
}, err => {
console.log(err);
});
});
}
我的登录组件是这个
constructor(
public authService: AuthService
) {
this.auth$ = this.authService.authState$;
}
<div *ngIf="auth$ | async as user">
-{{user | json}}-
</div>
所以,当我打电话
authService.doMicorosftLogin()
loading设置为“ true”,但登录成功后不会更改,但是如果我重试(没有reload页面),它将起作用。
步骤是
致电doMicorosftLogin()
loading = true
登录成功->没有任何反应
调用doMicorosftLogin()
loading = true
登录成功-> loading =假