angularzone.jsngzone

ngZone or zone.js: the place of monkey-patching?


I'm learning how ngZone works in Angular. I understood that it's doing monkey-patching of standard async operations(such as setTimeout).

But who is doing monkey-patching? zone.js library or Angular itself within ngZone? It would be great if you could show specific place in source code where it happens.


Solution

  • Angular runs the zone within zone.js, and zone.js provides a scope with patched API.

    You can yourself use zone.run(...) without anything from Angular and get all the effects of the patched API.

    See also https://github.com/angular/zone.js/

    The code that patches the timer https://github.com/angular/zone.js/blob/master/lib/common/timers.ts#L22