-
Notifications
You must be signed in to change notification settings - Fork 6.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
CdkPortalOutlet should resolve componentFactories through the portal's ComponentFactoryResolver #9712
Comments
Are you referring to For the first, it uses whatever For the second, it will use the |
I'm talking about My specific use case is a navigation menu outlet: Modules can bring in their own navigation components through route data. Obviously the outlet lives somewhere higher up in the hierarchy and doesn't know about
It'd be great to be able to pass a ComponentFactoryResolver to CdkPortalOutlet in case one needs to deal with sibling and child modules. |
…dkPortalOutlet Adds the ability for consumers to pass in a different `ComponentFactoryResolver` when attaching to a `CdkPortalOutlet` programmatically. Fixes angular#9712.
…dkPortalOutlet Adds the ability for consumers to pass in a different `ComponentFactoryResolver` when attaching to a `CdkPortalOutlet` programmatically. Fixes angular#9712.
@crisbeto you closed the linked PR stating that this wouldn't be necessary in Angular 6+. Thank you for your work! |
@crisbeto I have the same question as @j2L4e. Basically, as per angular/angular#14324, I am unable to attach component portals to my shared portal outlet when the component I want to render is declared within a lazy loaded module. Since the portal outlet’s component factory resolver does not know about the entry components from lazy loaded modules, I need to use the module’s component factory resolver. So I need a way to be able to pass the component factory resolver to the component portal, or the portal outlet’s attach method. The pull request did exactly that, and I can confirm (through monkey patching) that this indeed works for me. But even with Angular 6.1, I do not see how this is possible without being able to pass the factory; or without the outlet retrieving the factory from the injector that is passed through the portal. Could you clarify why you believe that the changes from that PR are no longer necessary for Angular 6? I might be wrong, but I haven’t been able to find a way around the component factory resolver. |
Probably. Have an API in mind? |
I was thinking of basically doing the same as in #9882 which we closed a while ago, because of Ivy. |
For what it’s worth, I am using the exact same strategy as in that pull request in a patched version running on 6.1 and that works completely fine. Having to pass an explicit component factory resolver to the |
Why make the resolver a parameter to |
The point of this is that you can attach various component portals to the same outlet. So you can attach compontent X of lazy-loaded module A using A’s component factory resolver, and in the next moment you can attach component Y of lazy-loaded module B using B’s component factory resolver. So the component factory resolver you choose is always strongly coupled to the component portal you want to attach. If this was an input, then you would have to move this logic to the parent component, and you would be pretty much defeating the purpose of component portals and the The component factory resolver being coupled to the component portal would probably be an argument for moving the component factory resolver reference into the component portal, instead of passing it while attaching. At that point, this might be an argument for @j2L4e’s original idea, to resolve the component factory resolver from the component portal’s injector. I don’t know if that actually works, but from my experiments, passing the injector to the component portal is not required to make it work. I have been using the outlet’s injector with a component from a different NgModule using that module’s component factory resolver, and that’s been working very well. So if the component factory resolver is moved to the component portal (instead of the |
That's a good point; you'd want the resolver to be associated with the |
…ted with portal Allows consumers to specify a their own `ComponentFactoryResolver` when creating a `ComponentPortal`. Previously we would only use the resolver from the `PortalOutlet`. Fixes angular#9712.
I just updated my application to Angular 7 and cdk 7.0.2 and wanted to migrate to this solution. However, I realized that the change that now made it into the release only applies to the So unfortunately, the fix for this does not work for me. Any chance we can get this ported to the |
Re-opening this for the change still needed in |
…irective Follow-up from angular#12677 where we missed to add the new functionality to the `CdkPortalOutlet` directive. Fixes angular#9712.
…irective (angular#13886) Follow-up from angular#12677 where we missed to add the new functionality to the `CdkPortalOutlet` directive. Fixes angular#9712.
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. |
Bug, feature request, or proposal:
At the moment,
CdkPortal
tries to resolveComponentFactories
via its own CFR which it got from its ownInjector
instance:It may happen that you'd like to attach a
ComponentPortal
with a lazily loadedentryComponent
that's not resolvable through thePortalHost's
CFR. It should then try to get a CFR instance from the Portal to resolve theComponentFactory
if it can't resolve it through its own:I'm not sure if this has any negative side effects.
The text was updated successfully, but these errors were encountered: