Skip to content
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

DIalogInjector and lazy-loaded modules Injectors #1765

Closed
eagle-dan1349 opened this issue Nov 8, 2016 · 11 comments
Closed

DIalogInjector and lazy-loaded modules Injectors #1765

eagle-dan1349 opened this issue Nov 8, 2016 · 11 comments
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround

Comments

@eagle-dan1349
Copy link

eagle-dan1349 commented Nov 8, 2016

Bug, feature request, or proposal:

[x] Bug

What is the expected behavior?

DialogInjector should be aware of Injector from lazy-loaded module

What is the current behavior?

DialogInjector is unaware of lazy-loaded module and attempts to inject services provided by lazy-loaded module result in 'No provider for ...' errors

What are the steps to reproduce?

  1. Create route to lazy loaded module.
  2. Provide service from lazy-loaded module.
  3. Declare dialog component in lazy-loaded module.
  4. Inject service to dialog component.
  5. Try to display dialog.
  6. Catch error.

Plunker template: http://embed.plnkr.co/eBQNsfV7jTys4THqfT77/

What is the use-case or motivation for changing an existing behavior?

I try to split my app into lazy-loaded modules.

Which versions of Angular, Material, OS, browsers are affected?

Angular: ~2.1.0
Material: ^2.0.0-alpha.9-3

@jelbourn jelbourn added the P2 The issue is important to a large percentage of users, with a workaround label Nov 9, 2016
@jelbourn jelbourn self-assigned this Nov 9, 2016
@jelbourn
Copy link
Member

jelbourn commented Nov 9, 2016

Thank you for your excellent bug report.

@karolmie1
Copy link

@jelbourn Any tips on how to circumvent this? Just recently stumbled uppon this problem. Shame its unlikely i can help fixing it.

@eagle-dan1349
Copy link
Author

eagle-dan1349 commented Jan 12, 2017

@karolmie1 I had to give up lazy loading until the issue is resolved

@jelbourn
Copy link
Member

@eagle-dan1349 I think the next release will fix this- we're getting rid of forRoot (#2556), so the lazily-loaded module can import MdDialogModule and it will get a new instance with the appropriate injector. You can install the latest SHA from https://github.com/angular/material2-builds to test it out.

@coder925
Copy link

Excellent! It works with the latest bits given that you are also importing MaterialModule in the lazy loaded sub-module. Thanks!

@elvisbegovic
Copy link

@eagle-dan1349 can you close this issue please, the new way is always import material module without forRoot() method, and internally material check for each service if token exist use it otherwise create new instance.

cc @jelbourn

@quedicesebas
Copy link

What about this with angular 8?

@DrewImm
Copy link

DrewImm commented Aug 28, 2019

@sebrojas14

What about this with angular 8?

In Angular 8, I solved the issue by adding MatDialogModule into the submodule's import array:

...
import { MatDialogModule } from '@angular/material/dialog';
...

@NgModule({
	declarations: [ TheDialogComponent ],
	imports: [
		...,
		MatDialogModule, // < Add this line!
		...
	],
	entryComponents: [ TheDialogComponent ]
})
export class TheSubModule {}

@joesleiman
Copy link

joesleiman commented Sep 5, 2019

@DrewImm
it didn't work for me. any new suggestion?

@Splaktar
Copy link
Member

I can't confirm that this is the case 100%, but there is some discussion about how Ivy may improve upon this behavior in angular/angular#14324 (comment).

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

No branches or pull requests

9 participants