I am trying to run angularjs and angular17+ side by side in a hybrid setup. I followed all guidelines and created a custom webpack config to be able to pack my angularjs files and my angular files. The app seems to work but as soon as i am trying to load an angular component using the downgrade guideline at https://angular.io/guide/upgrade#using-angular-components-from-angularjs-code i get the following error:
> angular.js:13708 NullInjectorError: R3InjectorError(Ng2AppModule)
[ComponentFactoryResolver$1 -> ComponentFactoryResolver$1]:
NullInjectorError: No provider for ComponentFactoryResolver$1!
at NullInjector.get (core.mjs:5605:1)
at R3Injector.get (core.mjs:6048:1)
at R3Injector.get (core.mjs:6048:1)
at NgAdapterInjector.get (static.mjs:1209:1)
at doDowngrade (static.mjs:771:1)
at static.mjs:798:1
at SyncPromise.then (static.mjs:633:1)
at Object.link (static.mjs:798:1)
at angular.js:1240:1
at invokeLinkFn (angular.js:9814:1)
Seems like the dependency injection is not working properly? any ideas how to solve this?
2
Answers
I found out the issue:
Downgrading the Angular 2+ components should be done in the Angular 2+ main.ts file and not in the AngularJs module.
You should put all downgrades after bootstraping Angular 2+ and before bootstrapping your AngularJs module.
Make also sure that the bundled js file of your angularjs code is put before the bundled Angular js file in your index.html.
See the downgradecomponent part below: Example of your angular2+ main.ts:
to work properly provide
*ComponentFactoryResolver*
inside app.config.tsfocus on providers section