gpt4 book ai didi

javascript - angular2 中的变化检测是否总是从根组件开始?

转载 作者:搜寻专家 更新时间:2023-10-30 21:24:44 25 4
gpt4 key购买 nike

Angular2

中考虑以下组件树结构
     A
B C
D E F G

如果 G 通过点击向 C 发出一个事件,而 C 没有继续该事件

html

<div (click)="update($event)"></div>

组件

@Output() myOutputName = new EventEmitter();

update(event) {
this.myOutputName.emit('some vlaue');
}

变更检测是在从A 开始的所有节点中运行还是在C 上开始变更检测并且只影响F G ?

最佳答案

YES, CHANGE DETECTION ALWAYS STARTS FROM ROOT COMPONENT

幻灯片 - http://pascalprecht.github.io/slides/angular-2-change-detection-explained/#/54

Data always flows from top to bottom, is because change detection is also always performed from top to bottom for every single component, every single time, starting from the root component

因此,如果 G 发出一个事件,

变更检测将从根组件开始,

A (A 中的变化检测)

B C (B、C 中的更改检测)

D E F G ( D、E、F、G 中的变化检测)

请记住,有多种方法可以处理变更检测。

但默认情况下,变化检测从根开始

进一步引用,

文章
1) http://blog.thoughtram.io/angular/2016/02/22/angular-2-change-detection-explained.html
2) http://victorsavkin.com/post/110170125256/change-detection-in-angular-2

关于javascript - angular2 中的变化检测是否总是从根组件开始?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36489764/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com