ExpressionChangedAfterItHasBeenCheckedError:与加载程序拦截器服务一起使用加载程序组件时

问题描述 投票:0回答:1

突然我开始出现以下控制台错误,而没有更改代码。

Expression has changed after it was checked. Previous value: 'ngIf: false'. Current value: 'ngIf: true'.

在此html行中

<div id="cover" *ngIf="show && (router.url === '/inventory/overview' || router.url === '/inventory/details')" class="loader-cover">

LoaderInterceptorService-从此服务显示变量已更改

如何解决此错误?

angular angular7
1个回答
0
投票

在您的@Component对象中添加以下行:changeDetection:ChangeDetectionStrategy.OnPush

像这样:

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: 'app-selector',
  templateUrl: './selector.component.html',
  styleUrls: ['./selector.component.scss']
})

并从'@ angular / core'导入ChangeDetectionStrategy

© www.soinside.com 2019 - 2024. All rights reserved.