Skip to content

feat: providing a way to get the component attached to a CdkPortalOutlet #9304

@noemi-salaun

Description

@noemi-salaun

Bug, feature request, or proposal:

Feature request

When attaching a ComponentPortal to a CdkPortalOutlet using the declarative syntaxe <ng-template [cdkPortalOutlet]="myComponentPortal">, there is no way to get the instance of the component, created by the directive.

The only way to get the component instance is to attach the portal programmaticaly, but it would seem that the cycle is not as clean as using the directive directly. When doing it in the ngOnInit, the view isn't initialized, and inside the ngAfterViewInit, I get the "change after it was checked" error.

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

Dynamically render a component, based on some type attribute. The developer can register it's own component to be rendered if the type matches. All these components implement the same interface and I need my parent component to access some methods in it. To do so, I need to get the instance created during the portal attachment.

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

Angular: 5.1.3
Cdk: 5.0.3
OS: Windows 10
TS: 2.4.2
Browser: Chrome 63

Metadata

Metadata

Assignees

Labels

P4A relatively minor issue that is not relevant to core functionsfeatureThis issue represents a new feature or feature request rather than a bug or bug fix

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions