突然我开始出现以下控制台错误,而没有更改代码。
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-从此服务显示变量已更改
如何解决此错误?
在您的@Component对象中添加以下行:changeDetection:ChangeDetectionStrategy.OnPush
像这样:
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
selector: 'app-selector',
templateUrl: './selector.component.html',
styleUrls: ['./selector.component.scss']
})
并从'@ angular / core'导入ChangeDetectionStrategy