angular - 即使调用 ChangeDetectorRef.DetectChanges 也不会触发 Angular 7 更改检测
问题描述
我的 Angular 7 应用程序中有这段代码:
在子组件中:
@Input() lstBlocks;
在父组件中,我将此列表传递为:
<block-container [lstBlocks]="lstBlockDtos"></block-container>
lstBlockDtos
是一个包含数组的数组。例如索引 0、1、2 等上的数组...
在父容器中,我正在替换其中一个嵌套数组的内容:
const dtosIndex = this.lstBlockDtos.findIndex(bDto => bDto.planDate === planDateFormatted);
this.lstBlockDtos[dtosIndex] = mblockDtos;
...哪里mblockDtos
是一个包含更多内容的新数组。
我的问题是,当我更改内部数组的内容时,更改检测对孩子不起作用。我已经实现了OnChanges
生命周期方法,但它没有按预期触发。我也尝试ChangeDetectorRef.DetectChanges
在更改内部数组的内容后立即调用,但更改检测仍然不起作用。
解决方案
推荐阅读
- python - 如何在 Python 中使用 .writer 填充行中的空白/空单元格?
- python - 使用 df1 作为 df2 的查找表,在 Python 中 df2 比 df1 有更多的唯一值
- c# - Xamarin 中的事件和委托表单父页面和子页面
- mysql - 如何在 SQL 中制作百分比列?
- amazon-web-services - 如何跟踪用户使用 AWS 上传的数据?
- azure - 如何使用与 Azure.Storage 之间的 HTTP 块文件传输?
- ads - Google Ad Manager (DFP) 将键值输入模板以在广告素材中显示自定义值
- php - 此代码是否建立数据库连接?
- google-app-engine - app.yaml env_variables 在云构建步骤期间可作为 env 访问
- reactjs - 为什么我不能将数组作为道具从一个 js 传递给另一个?