# In-depth: How do CDK Portals work?

DevFeed: [In-depth: How do CDK Portals work?](<https://devfeed.tech/articles/in-depth-how-do-cdk-portals-work-21330.md>)

Original publisher: [Read original article](<https://juri.dev/blog/2018/06/how-cdk-portals-work/>)

Published: 2018-06-25T00:00:00Z

Content type: tutorial

Language: en

Sources: [Juri Strumpflohner](<https://devfeed.tech/sources/juri-strumpflohner.md>)

Topics: [Tool](<https://devfeed.tech/topics/tool.md>), [Documentation](<https://devfeed.tech/topics/documentation.md>)

Tags: [angular](<https://devfeed.tech/tags/angular.md>), [angular-material](<https://devfeed.tech/tags/angular-material.md>), [cdk](<https://devfeed.tech/tags/cdk.md>), [change-detection](<https://devfeed.tech/tags/change-detection.md>), [template](<https://devfeed.tech/tags/template.md>), [view](<https://devfeed.tech/tags/view.md>)

## AI overview

The excerpt explains how Angular CDK portals render a template at another DOM location: a TemplatePortal holds a template reference and its ViewContainerRef, while a portal host receives the view and places it in the DOM. To build the template view manually, define an ng-template with a template reference variable, access it in ngAfterViewInit, and use ViewContainerRef.createEmbeddedView; an optional context object can pass data to the view. The excerpt notes that the embedded view can undergo change detection while in memory, but cuts off as it begins describing the portal host, so its implementation details are not available.

## Source excerpt

Lorem ipsum dolor sit amet