When and why to use a 'tick' in Angular 2?

后端 未结 3 1707
离开以前
离开以前 2021-01-01 12:13

I have seen the following is used in an Angular 2 component class:

setTimeout(()=>{}, 0);

That means, an empty function is called after

3条回答
  •  滥情空心
    2021-01-01 12:31

    setTimeout(()=>{}, 0);
    

    Causes Angular to run change detection for the whole application, like ApplicationRef.tick

    zone.js patches async APIs (addEventHandler, setTimeout, ...) and runs change detection after a callback was completed.

提交回复
热议问题