Uncaught Error: Trying to get the Angular injector before bootstrapping an Angular module.

David Graf
The road to Angular
1 min readFeb 22, 2018

--

In our Hybrid Angular app, we switched from UpgradeModule to DowngradeModule to avoid performance issues (https://pr18487-aedf0aa.ngbuilds.io/guide/upgrade-performance).

This change fixes the Hybrid App performance issues perfectly, but it has one downside:

While it is possible to downgrade injectables, downgraded injectables will not be available until the Angular module is instantiated. In order to be safe, you need to ensure that the downgraded injectables are not used anywhere outside the part of the app that is controlled by Angular.

For example, it is OK to use a downgraded service in an upgraded component that is only used from Angular components, but it is not OK to use it in an AngularJS component that may be used independently of Angular.

As a consequence, it is not possible to inject downgraded services in factories because factories are created at bootstrap time.

Fortunately, it is still possible to inject downgraded services dynamically in ng1 factories because the ng1 factory is not used before the downgraded component is bootstrap:

$injector.get('myNgService').myFunction('/');

--

--