Request: Example of passing complex content projection
See original GitHub issueHi,
I’m looking to use NGXD to load dynamic components and content provided by a headless CMS like Contentful, but I’ve come into a bit of an issue where I’m struggling to figure out how to use content projection with the dynamically loaded components.
I have an X Column component that can host a number of predefined components, some of which are able to take complex content using ng-content
. Is this something this package can handle? And is it possible to get an example?
Here’s some demo code I’ve created to explain the situation https://stackblitz.com/edit/angular-simple-dynamic-8emvyb?file=src/app/app.module.ts
Issue Analytics
- State:
- Created 3 years ago
- Comments:19 (10 by maintainers)
Top Results From Across the Web
Content projection - Angular
Content projection is a pattern in which you insert, or project, the content you want to use inside another component. For example, you...
Read more >Content Projection in Angular - Medium
Conditional Content Projection refers to creating a component into which you can conditionally project into one or more slots/directives.
Read more >Content Projection in Angular with Ng-Content
The solution for the above-mentioned problem is Content Projection, i.e., we will project or send in the complete content from the parent and...
Read more >Content Projection in Angular - This Dot Labs
The simplest way to do content projection is to use a single "slot" or area where we pass data in. Note that you're...
Read more >From transclusion to content projection - Telerik Blogs
In more complex situations it might not be enough to simply use attribute bindings to pass in data, but there's the need for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello, @ChazUK
If you want to have using ng-content with dynamic components, you have to create
projectableNodes
by self. I’ll explain to you what do you need to do.<ng-template>
and put an<ng-content>
in it.TemplateRef
using by@ViewChild()
decorator.projectableNodes
. In order to do this you have to create aViewRef
of theTemplateRef
and getrootNodes
. Don’t forget to place theprojectableNodes
in*ngxComponentOutlet="content: projectableNodes"
.@xeladotbe this question is out of scope for this issue. In short you can’t apply any dicrectives to html content from CMS. But you can handle link click and use Router api. See this example https://stackblitz.com/edit/angular-inner-html-links?file=src/app/app.component.ts