Angular interpolated value display not updating when changed in timeout

做~自己de王妃 提交于 2019-12-04 19:43:24

This is the expected action. The javascript method Window setTimeout is a Window command. This means that it is called outside the main zone.js thread (by which I mean the general change detection contained out of box in an Angular application), which is the expected plan. If you would like to contain your setTimeout() method you need to assign it to a variable contained inside your Angular TypeScript application.

This behavior is the most distinct when using a similar method in the same family of functions called from window: the Window setInterval() Method

You are able to contain this, and similar Window methods. The setTimeout() command needs the ChangeDetectorRef attached to it to detect changes in order to listen to Events Emitted. You can also insert commands by assigning the executed method to a component variable (similar to this answer on how to stop setInterval() after a component is destroyed here).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!