简体   繁体   English

如何在代码执行过程中强制视图更新?

[英]How to force view update in middle of code execution?

Every once in a while I have a situation where my code changes some variable binded to the view, or even change some attribute of a Dom element, but the view renders only when all the code is executed, when I usually I don't need the effect anymore, like for example an animation for an Ajax data load. 我偶尔会遇到这样的情况,我的代码更改了绑定到视图的某些变量,甚至更改了Dom元素的某些属性,但是视图仅在执行所有代码时才呈现,通常我不需要效果不再一样,例如Ajax数据加载的动画。

Is there a way or a command that forces the DOM or Angular to revalidate its bindings or simple refreshes the view? 有没有一种方法或命令可以强制DOM或Angular重新验证其绑定或简单地刷新视图?

If I understand your problem correctly it looks like you need to run change detection manually. 如果我正确理解了您的问题,则看起来您需要手动运行更改检测。

ChangeDetectorRef.detectChanges() would trigger change detection for view and child components. ChangeDetectorRef.detectChanges()将触发视图和子组件的更改检测。

ChangeDetection Docs 变更检测文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM