angular - Angular 和 NGXS 实验室操作正在执行:ExpressionChangedAfterItHasBeenCheckedError
问题描述
这是我的仓库:https ://github.com/richarddavenport/why
我无法在 stackblitz.com 或 codesandbox.io 上重现此问题。
我收到了可怕的错误:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: '[object Object]'. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook?
我的子组件视图:
<div>{{fetching$ | async | json}}</div>
<form [formGroup]="form" ngxsForm="state.form"></form>
我的动作处理程序处于状态:
@Action(FetchAction)
fetchAction() {
console.log('Dispatched --> fetch');
return of(true).pipe(delay(15000));
}
如果delay()
像这样将 更改为 0 ,则不会出现错误:
@Action(FetchAction)
fetchAction() {
console.log('Dispatched --> fetch');
return of(true).pipe(delay(0));
}
如果从子组件视图中删除表单,则不会出现错误:
<div>{{fetching$ | async | json}}</div>
有些动作从ngxsForm
指令中调度以最初同步状态,但我不知道它们是否导致了问题。
解决方案
设置组件更改检测以ChangeDetectionStrategy.OnPush
解决此问题。
推荐阅读
- mongodb - Node.js Mongoose:值不代表设置的数据,但数据库已更改
- php - Wordpress - WooCommerce - 在桌面外显示“添加订单注释”表单
- batch-file - 如何将变量保存到批处理文件?
- java - spring:如何将角色应用于现有的 JWT 令牌
- python - 如何使这个不断变化的数据框更快?
- c# - .NET Core Web API - 无法插入记录调用 Oracle 存储过程
- css - 我如何将 Material-UI 托管样式应用于非 Material-ui、非反应元素?
- javascript - 在 React 中使用 JS 在 mouseOver 上播放视频
- swift - 加载图像时 UITableViewCell 显示错误的图像
- javascript - 将对象数组中的一个属性映射到不同对象数组中的另一个对象