[sitecore-jss-angular] Fixed missing ngModuleRef in lazy loaded components #1717
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Components declared in a lazy loaded Module are no longer able to inject Providers from that Module, they get a NullPointer exception from Angular Injection.
Description / Motivation
When the
PlaceholderComponent
creates the Rendering Components, it is missing thengModuleRef
(as describen in the Angular documentation for createComponent). Without the ModuleRef the Component falls back to the App Module injector, which does not have the providers defined in the lazy loaded Module.This change adds back the
ngModuleRef
when a Rendering Component is being created by the PlaceholderComponent, therefore using the right injector. It used to work in older versions of sitecore-jss-angular and broke with the following commit 4959479. In the older version thecomponentFactory
already included thengModuleRef
, but it's missing in the newcomponentImplementation
.Testing Details
I built my forked repo locally, integrated it into our project and manually tested it successfully (NullPointer exceptions were no longer thrown for lazy loaded components). Unfortunately I don't have the time or capacity to add new Unit Test's.
Types of changes