3

I'm mainly interested in the impact of this line in their documentation:

Unlike UpgradeModule, downgradeModule() does not bootstrap the main AngularJS module inside the Angular zone.

Does this mean that just the initial bootstrap of the application will run outside of the Angular zone? Or, will the services, factories, etc that get instantiated also run outside the Angular zone?

If it's just the initial bootstrap, then how do you run specific pieces of the AngularJS side outside of the Angular zone (mainly for performance reasons)?

A simple example that explains why I'm confused is an AngularJS service that does something like this:

element.on('click', handlerFn);
function handlerFn () {
    scope.$apply(function () {
        // update some scope binding
    });
}

In this example, the click handler is happening outside of the change detection in AngularJS, which is why the scope.$apply is required.

However, the Angular change detection is a different story:

First, there are events that are patched to automatically work inside of the angular zone.

Second, I've noticed that if the service is called from within an UpgradeComponent, it's inside of the Angular zone, but it appears that if it's called from another part of the application, that is not originating from an UpgradeComponent, then it is not in the zone.

Is this only because it's being called by an upgraded component? And if so, is there some standard workaround for having this code run outside the Angular zone, like during the bootstrap or in the UpgradeComponent? Or is it bad practice to even try to do this (like if it would cause syncing issues between Angular and AngularJS)?

I can try to produce a minimal example if necessary.

Edit: This isn't exactly the environment I'm working with (in terms of angular versions), but here's an example of the behavior I'm talking about with the angular zone.

CShark
  • 1,562
  • 1
  • 16
  • 27

0 Answers0