我有两个布局,每个布局都加载条件:
<app-layout-w *ngIf="!p || p === 1">
<router-outlet></router-outlet>
</app-layout-w>
<app-layout-o *ngIf="p === 6">
<router-outlet></router-outlet>
</app-layout-o>
还有ts:
ngOnInit() {
const subscription = this.authService.getToken().subscribe(token => {
const payload = new NbAuthJWTToken(token.getValue(),
token.getOwnerStrategyName(), token.getCreatedAt()).getPayload();
if (payload) {
this.p = payload.provider;
}
});
this.userService.isAuthenticated.subscribe(isAuthenticate => {
if (!isAuthenticate) {
this.openDialog();
}
});
}
我的错误是:
错误类型错误:"this.container为null">
错误是由openDialog()
引起的。我注意到的是,布局根本没有加载。我正在使用ChangeDetectionStrategy.OnPush
。
注释掉openDialog()
避免了错误,但出现了一个空白的白色页面。没有错误,也没有加载
this.userService.isAuthenticated.subscribe(isAuthenticate = > {
if (!isAuthenticate) {
this.changeDetectorRef.detectChanges();
this.openDialog();
}
});