我想重定向到我的家庭组件认证后。重定向成功,但主页组件不呈现。如果我将this.router.navigate移动到订阅块外部,它将正确呈现。路由器导航重定向后身份验证不呈现组件
export class LoginComponent implements AfterViewInit {
constructor(private router: Router,
private authService: AuthenticationService) {
this.authService.authenticationStream().subscribe(isAuthenticated => {
if (isAuthenticated) {
this.router.navigate(['/home']);
}
});
}
}
在Chrome浏览器开发工具,我可以看到所有的家庭成分的模板除了一个ngFor块:
<md-grid-tile *ngFor="let tile of CONFIG.tiles">
{{ tile }}
</md-grid-tile>
我可以验证CONFIG.tiles填充。
为什么在导航后不会呈现ngFor块,特别是在Observable订阅中导航调用?
编辑:添加了AuthenticationService代码:
export class AuthenticationService {
constructor(private http: HttpService,
private store: Store<AppStore>) {
}
authenticate(): void {
let uri = 'http://uri.com'
this.http.post(uri).subscribe(() => {
// Dispatch event to ngrx store if user is successfully authenticated
this.store.dispatch({type: AUTHENTICATED});
});
}
authenticationStream(): Observable<boolean> {
// Emits events from dispatch calls
return <Observable<boolean>> this.store.select(AUTHENTICATION);
}
}
什么是'authService'authenticationStream'? –
'authService.authenticationStream()'返回一个表示验证状态的布尔值的Observable流 –
请添加显示它的代码 –