Skip to content

docs-bug(CdkPortal): @ViewChild() returns undefined when using *cdkPortal instead of <ng-template cdkPortal>  #21092

Open
@NicolasThierion

Description

@NicolasThierion

The official doc says:

The content of this template is captured by the portal.

The content of this template is captured by the portal.

A component can use @ViewChild or @ViewChildren to get a reference to a CdkPortal.

However, @ViewChild('theElementRef') binds to undefined when I use the *cdkPortal notation,
while it works when I use <ng-template cdkPortal>

I suspect *cdkPortal makes the element to leave the page before afterViewInit().
Maybe the documentation should encourage using the <ng-template> form instead.

Affected documentation page: https://material.angular.io/cdk/portal/overview#portals-in-practice

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/portaldocsThis issue is related to documentationgood first issueThis issue is a good place to start for first time contributors to the projecthelp wantedThe team would appreciate a PR from the community to address this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions