本文介绍了如何强制组件的重新渲染的角2?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何强制组件的重新渲染的角2?
对于终极版工作调试目的,我想强制组件重新渲染它的观点,这可能吗?
How to force a component's re-rendering in Angular 2?For debug purposes working with Redux i'd like to force a component to re-render it's view, is that possible?
关于
肖恩
推荐答案
渲染是变化检测的一部分。要强制变化检测,这里有一些选择:
Rendering is part of change detection. To force change detection, here are some options:
- - 类似于
$ rootScope $申请(回调)
- 也就是说,评价角度2区域内的回调函数。我想,但我不知道,这最终执行回调函数后检查全组件树。 - ChangeDetectorRef.detectChanges() - 类似于
$ $范围摘要()
- 即只检查该组件及其子
- ApplicationRef.tick() - similar to Angular 1's
$rootScope.$digest()
-- i.e., check the full component tree - NgZone.run(callback) - similar to
$rootScope.$apply(callback)
-- i.e., evaluate the callback function inside the Angular 2 zone. I think, but I'm not sure, that this ends up checking the full component tree after executing the callback function. - ChangeDetectorRef.detectChanges() - similar to
$scope.$digest()
-- i.e., check only this component and its children
您可以注入 ApplicationRef
, NgZone
或 ChangeDetectorRef
到您的组件。
You can inject ApplicationRef
, NgZone
, or ChangeDetectorRef
into your component.
有关您的特定情况下,我会如果只有一个组件正在改变建议最后的选择。
For your particular scenario, I would recommend the last option if only a single component is changing.
这篇关于如何强制组件的重新渲染的角2?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!