what triggers the change detection in an angular application when calling markForChange()...

Discussão em 'Angular' iniciado por noman tufail, Dezembro 11, 2024.

  1. noman tufail

    noman tufail Guest

    I am using the following code inside my component's constructor. The component is using the OnPush change detection strategy. As we can see, setTimeout executes outside the Angular zone, meaning zonejs will not be aware when the setTimeout operation has completed.

    In this case, who informs Angular that something has changed and that it should trigger a change detection cycle?

    I understand that markForCheck is responsible for marking the component and its ancestors as dirty, but my confusion is: how does Angular know when to start change detection since setTimeout is running outside the Angular zone?

    this.zone.runOutsideAngular(() => {
    setTimeout(() => {
    this.count = 5;
    this.cdr.markForCheck();
    }, 3000);
    })

    Continue reading...

Compartilhe esta Página