我在应用内部的某处注销后出现ExpressionChangedAfterItHasBeenCheckedError. Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.
错误,front
app.component.ts
中的{4}} getter在其视图中发生了变化。
另外,如果我启用生产模式,则不会出现错误!这一切都可以,但我不想看到错误。
app.component.html
<div class="col-xs-12" [class.space]="!front">
<router-outlet></router-outlet>
</div>
app.component.ts
get front() {
if (localStorage.getItem("user") === "\"admin\"") {
return false;
}
return true;
}
答案 0 :(得分:-1)
将整个代码放在setTimeout
这样的
get front() {
return new Promise(resolve => setTimeout(() => {
if (localStorage.getItem("user") === "\"admin\"") {
resolve(false);
}
resolve(true);
}, 200));
}