如何强制组件的重新渲染的角2? [英] How to force a component's re-rendering in Angular 2?

查看:291
本文介绍了如何强制组件的重新渲染的角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:

  • 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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆