question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CdkPortalOutlet should resolve componentFactories through the portal's ComponentFactoryResolver

See original GitHub issue

Bug, feature request, or proposal:

At the moment, CdkPortal tries to resolve ComponentFactories via its own CFR which it got from its own Injector instance:

const componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);

It may happen that you’d like to attach a ComponentPortal with a lazily loaded entryComponent that’s not resolvable through the PortalHost's CFR. It should then try to get a CFR instance from the Portal to resolve the ComponentFactory if it can’t resolve it through its own:

const componentFactory = portal.injector.get(ComponentFactoryResolver).resolveComponentFactory(portal.component);

I’m not sure if this has any negative side effects.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
jelbourncommented, Aug 13, 2018

That’s a good point; you’d want the resolver to be associated with the ComponentPortal in that case. That makes more sense anyway, since TemplatePortal doesn’t use the resolver at all. The simplest thing would probably be adding a ComponentFactoryResolver as a 4th argument to the constructor for ComponentPortal. I would shy away from trying to get it from the given injector because someone might want to use an injector from a totally different part of the application tree.

2reactions
j2L4ecommented, Jun 11, 2018

@crisbeto you closed the linked PR stating that this wouldn’t be necessary in Angular 6+. Could you elaborate on how resolving factories has changed?

Thank you for your work!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use CdkPortalOutlet with component in different module
Currently, I'm using Module Factory and component factory. Is it possible to use Angular portals and load the component's module?
Read more >
Inject dynamic content in Angular components with portals
Learn how to dynamically render content in your Angular components using Angular CDK portals in this in-depth tutorial.
Read more >
Angular CDK Portals - Medium
The @angular/cdk contains a concept called portals. In this post I'll attempt to explain the concepts of a Portal, and when they should...
Read more >
Here is what you need to know about dynamic components in ...
We start with the comparison of dynamic components functionality in Angular and ... It's a job of a compiler to resolve all the...
Read more >
UNPKG - @angular/cdk
@angular/cdk/bundles/cdk-portal.umd.min.js.map ... Injector | null;\n\n /**\n * Alternate `ComponentFactoryResolver` to use when resolving the associated ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found