Angular:这个关于 @Input 更改时运行更改检测的声明是否正确?
这个网站说:
在默认的变更检测策略中,Angular 将运行变更 每当 @Input() 数据更改或修改时检测器
但实际上,只有在以下三个条件下才会触发更改检测(正如同一网站之前所说的那样):
- 任何浏览器事件(点击、按键等)
- getInterval() 和 setTimeout()
- 通过 XMLHttpRequest 进行 HTTP 请求
我的理解是,仅在上述三种情况下才会触发更改检测,然后 Angular 检查模板绑定中存在的数据是否已更改或不。如果它发生了变化,它会重新呈现该组件的视图。我假设如果绑定是到子组件中的属性,那么如果在子组件的模板内使用该绑定,则该子组件的 UI 也将重新呈现。
因此(与开头的语句不同),当 @Input 更改时,更改检测不会运行(但仅在给定的三个条件下)。 在更改检测的执行中,@Input 更改被检测到。我说得对吗?
This site says:
In the default change detection strategy, Angular will run the change
detector any time @Input() data is changed or modified
But in reality, change detection is triggered only on the following three conditions (as the same site says a little before):
- any browser event (click, keyup, etc.)
- getInterval() and setTimeout()
- HTTP requests via XMLHttpRequest
What I understand is that change detection is triggered only in the above three cases and then Angular checks if the data present in template bindings has changed or not. If it has changed, it re-renders the view for that component. I'm assuming that if the binding is to a property in a child component, then that child component's UI will also be re-rendered if that binding is being used inside the child component's template.
So (unlike the statement at the start), change detection is NOT run when @Input
changes (but only in the given three conditions). Its in the execution of change detection that @Input changes are detected. Am I right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论