【发布时间】:2020-07-13 01:45:52
【问题描述】:
虽然我知道ERROR 发生的原因,但是,我想知道如何在以下情况下克服:
我在app.component 中有一个通用加载器。对于某些子路由,它将在ngOnInit 生命周期中更新加载器值,直到获取记录。另外,我不想使用resolver,因为我正在解析组件中的查询参数,然后传递给服务以获取记录。
ERROR是由于加载器的默认值为false,在子组件生命周期ngOnInit钩子期间变为true。
请看下面的sn-p:
// app.component.ts
viewModel = {
showLoader: false
};
ngOnInit() {
this.eventService.on(ApplicationEvents.SHOW_FULL_PAGE_LOADER, (value) => {
this.viewModel.showLoader = value;
});
}
// app.component.html
<div class="full-page-loader" *ngIf="viewModel.showLoader"><em class="fa fa-cog fa-spin loader-icon"></em></div>
以下是来自延迟加载子组件的 sn-p:
ngOnInit() {
this.loadData();
this.cart = this.cartService.getCart();
}
private loadData() {
this.eventService.showFullPageLoader(); // <-- This will emit an event to show the loader
this.umrahDataService.getServices(UmrahServiceType.Visa).then((resp) => {
this.visas = resp.map((v) => {
v.image = '/assets/img/umrah/visa-processing.jpg';
return v;
});
this.eventService.hideFullPageLoader();
this.actionInProcess = false;
}).catch((er) => {
this.alertService.alert('SERVER_ERROR');
this.eventService.hideFullPageLoader();
this.actionInProcess = false;
});
}
错误错误:ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。以前的值:'ngIf: false'。当前值:'ngIf: true'。 在 viewDebugError (core.js:19629) 在表达式ChangedAfterItHasBeenCheckedError (core.js:19617) 在 checkBindingNoChanges (core.js:19833) 在 checkNoChangesNodeInline (core.js:29533) 在 checkNoChangesNode (core.js:29522) 在 debugCheckNoChangesNode (core.js:30126) 在 debugCheckDirectivesFn (core.js:30054) 在 Object.eval [as updateDirectives] (AppComponent.html:3) 在 Object.debugUpdateDirectives [as updateDirectives] (core.js:30043) 在 checkNoChangesView (core.js:29421)
虽然我也尝试了 BehaviorSubject 和 async 管道,但这也无济于事。
期待反馈。
谢谢
【问题讨论】:
-
确切的异常消息是什么?
-
@AshokanSivapragasam 更新了问题。请检查。
标签: angular angular-lifecycle-hooks