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

RootInjector should append LazyModule's entryComponents [feature request] #17168

Closed
renatoaraujoc opened this issue Jun 2, 2017 · 9 comments
Closed
Labels
area: core Issues related to the framework runtime feature Issue that requests a new feature
Milestone

Comments

@renatoaraujoc
Copy link

renatoaraujoc commented Jun 2, 2017

I'm submitting a ... (check one with "x")
[ ] bug report => search github for a similar issue or PR before submitting
[X] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
If you have a singleton service that uses a ComponentFactoryResolver provided by the App's RootInjector to dynamically create components and you wish to create an entryComponent declared in a lazy module, this will fail because the root injector does not know about it.

Expected behavior
This is actually the expect behavior considering that the root injector will not know about entryComponents known by the child injector.

What is the motivation / use case for changing the behavior?
The motivation is to leverage the complexity to create dynamic components though the modular design of Angular is correct.

Angular version: 2.4.9

Proposed solution: Even though this goes against the modular design adopted by Angular itself, I think that the complexity provided to create dynamic components could be softened by simply appending the LazyModule's entryComponents to the RootInjector's entryComponents and to avoid flooding the RootInjector, whenever you navigate out (which destroys the LazyModule), the previously injected entryComponents would be erased from the array.

Simply talking:

  1. Page is loaded -> RootInjector is created.
  2. Issues a navigation which activates a LazyModule -> ChildInjector is created.
  3. RootInjector.entryComponents.append(childInjector.entryComponents)
  4. Issues a navigation to somewhere else -> LazyModule is no longer necessary, thus destroyed.
  5. RootInjector.entryComponents.destroyLastAppendedEntryComponents()

Hope I could suggest something good.

Thank you!

@hansl hansl added the area: core Issues related to the framework runtime label Jun 15, 2017
@chuckjaz chuckjaz added the feature Issue that requests a new feature label Jun 20, 2017
@0x70b1a5
Copy link

+1, I spent hours hunting this bug down only to discover it's impossible to fix without abandoning the modular paradigm. Not a good look!

@jmcclanahan
Copy link

@0x70b1a5 - it's very possible while keeping things modular. See #14324. Though it would be nice to have this built into the framework.

@renatoaraujoc
Copy link
Author

I'd seriously love to have this implemented. Even though it breaks the modular design, it would make life 10 timer easier. I leveraged the solution by passing the childInjector to the service and then ask for the ComponentFactoryResolver for the component I want to render. It's "hackish" but works...

@elvisbegovic
Copy link
Contributor

@renatoaraujoc +1
I do exactly same and code is very weird and not easy to understand/maintain

as said if child injector (from lazyload) is required by some usecases we can keep entryComponents[] but I would ask new options like entryComponentsRoot[]

hope we'll receive news asap, i'm at 10% of my app and it is already big (more than 50 lazyload/module)

@Agrumas
Copy link

Agrumas commented Aug 25, 2017

Agree, the current behavior is unexpected and inconvenient especially working with modals in lazy loading modules. I have chosen to use https://github.com/ng-bootstrap/ng-bootstrap modals to avoid dealing with this.

@ngbot ngbot bot added this to the Backlog milestone Jan 23, 2018
@hansl
Copy link
Contributor

hansl commented Feb 28, 2018

I was just triaging this issue, I don't have context or information. As it goes, having it on the backlog is the first step to resolve, but it might sit there longer.

@lucasbasquerotto
Copy link

Perhaps a similar approach to what is done now in Angular6 with Injectables() using providedIn: 'root' could work.

Related #23819

@pkozlowski-opensource
Copy link
Member

This is the same issue as #14324, let's track it one place. I'm going to copy over the original description of this issue into #14324.

@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 Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: core Issues related to the framework runtime feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

9 participants