Skip to content

CdkPortalOutlet attachComponentPortal not render portal to outlet when portal have viewContainerRef #17650

@keatkeat87

Description

@keatkeat87

actually, I m not 100% confirm this is a bug or is by design. because document not very clear for this part.

Reproduction

https://github.com/keatkeat87/ng-mat-portal-outlet-issue
portal outlet

Expected Behavior

the portal should render in outlet not view container.

Actual Behavior

the portal render in view container.

more details:
I check the source code, class CdkPortalOutlet
image
as the comment said that
// If the portal specifies an origin, use that as the logical location of the component
// in the application tree. Otherwise use the location of this PortalOutlet.
if i not wrong, logical location is not equal to render location, so in this part, should have some code to move the element to outlet location.
i think it should work same as DomPortalOutlet
image
in the end, move element to outlet.
another interesting thing is in class CdkPortalOutlet
when we attach a templatePortal, it just ignore the templatePortal viewContainerRef.
image
it work not same as attach a component portal. it really make user confusing.

Environment

  • Angular: 9.0.0 rc1
  • CDK/Material: 9.0.0 rc 0
  • Browser(s): chrome latest
  • Operating System (e.g. Windows, macOS, Ubuntu): windows 10

Metadata

Metadata

Assignees

Labels

P2The issue is important to a large percentage of users, with a workaround

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions