angular - 变更检测策略在 Angular 中的工作原理
问题描述
如果我有多级组件,例如更改检测策略如何工作:
应用根组件
var data = {
name:"ajai"
}
<app-root>
<first-child [input]="data">
</first-child>
</app-root>
First-Child-component.html
{{data}}
<second-child> </second-child>
在 first-child 组件中,我们将调用 second-child 作为子组件。
第一个子组件.ts
@Input('data') data = {}
如果我更改 App-component 中数据的值,它将重新渲染整个树。所以第一个子组件我正在使用更改检测策略 OnPush,因此如果从应用程序组件进行的任何更改都不会影响其子组件渲染 dom。更新值我只是使用 changeDetectorRef detectChanges 所以数据得到改变 通过这样做实际上在这个树渲染中发生了什么以及性能如何增加
解决方案
推荐阅读
- python - 在 ubuntu 20.04 LTS 上将文本转为语音听起来很奇怪
- reactjs - 无法使用某些参数链接到 SPO 页面上的 Web 部件
- java - 如何从列表中获取值
并将其存储为双 - unit-testing - 在测试中找不到 RadioListTile
- reactjs - CSS 模块在 Jest 和 Enzyme 的测试中没有按预期工作,使用 create-react-app
- email - 如何在显示时知道邮件是否已发送或保存?
- r - 在 R 中基于多列创建列
- c# - IHM 与 CQRS+ES 的 Api 通信
- java - 材料容器变换过渡在背压上不起作用
- javascript - 字符串混淆