-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
defer loading a component with NgModule with providers throws error #52876
Comments
@naveedahmed1 thanks for reporting the issue. Could you please provide a minimal repro as well (for example, using https://stackblitz.com/), so that we can investigate it further? |
Thank you @AndrewKushnir for looking into it, here's the repro https://stackblitz.com/edit/stackblitz-starters-hmotk2?devToolsHeight=33&file=src%2Fmain.ts |
Looks like this is an issue with the library swimlane/ngx-charts#1733 |
Thank you @JeanMeche for quick reply. I have also added the code which lazily loads the component using import statement. if you could please try uncommenting it and see it works perfectly. |
Something is messing up the providers. Having I'll let Andrew confirm or deny, but this looks like a poor implementation to me. The service is provided by a nested module. flowchart RL
Z[NgxChartsModule] --> |imports|A
A[ChartCommonModule ] -->|imports|C[TooltipModule]
C --> |provides|InjectionService
|
I've got a smaller repro : https://stackblitz.com/edit/angular-or9ksy Here the injection is broken when the |
Thank you @JeanMeche for the update.
The service is Tooltip Service, right? if so I think its normal for Dynamically creating component using |
@naveedahmed1 thanks for additional information. I've reproduced the problem and will work on a fix. Will keep this thread updated. |
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
@AndrewKushnir will this fix be a part of v17.0.4? |
@naveedahmed1 no, the fix will be released later, since it needs a bit more research. As a possible temporary solution, you can try using the |
Very different circumstances, but similar error as this provider / injection issue I reported from v16. Wonder if they're related in some way (#51070) |
Same issue, only error when use defer NullInjectorError: R3InjectorError(_AppModule)[InjectionToken mat-select-scroll-strategy -> InjectionToken mat-select-scroll-strategy]: |
Same issue here with CurrencyPipe. Reproduction: https://stackblitz.com/edit/stackblitz-starters-wbseoe?file=src%2Fmain.ts |
@kkachniarz220 injecting pipe is a bad practice, you should rely on the underlying
|
Hmm, why it's a bad practice? Angular |
@kkachniarz220
|
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves angular#52876.
…block (#52881) Currently, when a `@defer` block contains standalone components that import NgModules with providers, those providers are not available to components declared within the same NgModule. The problem is that the standalone injector is not created for the host component (that hosts this `@defer` block), since dependencies become defer-loaded, thus no information is available at host component creation time. This commit updates the logic to collect all providers from all NgModules used as a dependency for standalone components used within a `@defer` block. When an instance of a defer block is created, a new environment injector instance with those providers is created. Resolves #52876. PR Close #52881
FYI, this issue should be fixed by 5712352, the fix will be released as a part of v17.2.3 next week. Please reopen (or create a new ticket) if the problem still exists after updating to v17.2.3. |
Thank you so much @AndrewKushnir :) |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
Yes
Description
When defer loading a component with NgModule with providers throws error:
Whereas lazyloading same component with
import
works just fine.Parent component:
Parent component template
Child Component
Dynamically loading component works perfectly:
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
Anything else?
No response
The text was updated successfully, but these errors were encountered: