[英]ExpressionChangedAfterItHasBeenCheckedError error because of loader interceptor in angular 6
I have an angular 6 project. 我有一个角度为6的项目。 And I create an interceptor for showing 'loading' panel.But because of this loading panel, I'm taking this error ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'
我创建了一个拦截器来显示“正在加载”面板。但是由于这个正在加载面板,我遇到了这个错误ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'
.How can I fix this? ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'
如何解决此问题?
My interceptor 我的拦截器
export class LoaderInterceptor implements HttpInterceptor {
constructor(private ch: CommonHelper) { }
intercept(request: HttpRequest < any >, next: HttpHandler): Observable < HttpEvent < any >> {
this.ch.showLoader();
return next.handle(request)
.pipe(
tap((event: HttpEvent<any>) => {
if (event instanceof HttpResponse) {
this.ch.hideLoader();
}
}, (error: any) => {
if (error instanceof HttpErrorResponse) {
this.ch.messageHelper.showErrorMessage('Error Occured');
}
this.ch.hideLoader();
})
);
}
}
My show and hide methods 我的显示和隐藏方法
showLoader() {
this.globals.displayLoader = true;
}
hideLoader() {
this.globals.displayLoader = false;
}
My layout.html 我的layout.html
<div class="loading-screen" *ngIf="ch.globals.displayLoader">
<div class="loading-loader"></div>
</div>
Try to put your method to show/hide in setTimeout, like this - 尝试将您的方法显示/隐藏在setTimeout中,如下所示-
setTimeout(() => {this.ch.hideLoader();}, 0)
For more explanation refer here - 有关更多说明,请参见此处-
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.