【发布时间】:2018-08-25 12:31:03
【问题描述】:
来自这两个帖子:
- The mechanics of DOM updates in Angular
- Angular 2 Performance: Is it better to bind with a data member than a function?
我了解发生“更改检测”时 DOM 是如何更新的。我从"Everything you need to know about change detection in Angular" 不明白的一点是 Angular 如何跟踪函数内部使用了哪些属性,因此何时应该运行“更改检测”。
假设这是父组件视图。
<child [prop]="func()"></child>
func() 在哪里
func() { return this.parentProp }
和parentProp 尚未在模板中使用。如果parentProp 被服务更改,Angular 怎么知道func() 依赖于parentProp,因此应该触发“更改检测”并更新视图。
【问题讨论】:
标签: angular angular-changedetection