How to wrap component which uses ng-content
See original GitHub issueBug description:
It’s not possible currently to wrap any component of the library which uses ng-content
/transclusion. This seems be caused by @ContentChildren
which can’t query 2+ levels of transcluded content.
So the following does not work:
@Component({
selector: 'my-accordion',
template: `
<ngb-accordion>
<ng-content></ng-content>
</ngb-accordion>
`
})
export default class MyAccordionComponent {}
And used as <my-accordion><ngb-panel>Hello world<ngb-pabel></my-accordion>
because ngb-panel
can’t be queried by ngb-accordion
. Maybe using { descendants: true }
with @ContentChildren(NgbPanel)
could solve this issue.
How would you suggest to wrap components?
Version of Angular, ng-bootstrap, and Bootstrap:
Angular: 2.4.5
ng-bootstrap: 1.0.0-alpha.19
Bootstrap: Bootstrap 4 alpha6
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:11 (3 by maintainers)
Top Results From Across the Web
Angular ng-content and Content Projection: A Complete Guide ...
In this post, we are going to learn how to use this feature to design components that have a very simple but still...
Read more >angular - How to conditionally wrap a div around ng-content
import { Component, Input } from '@angular/core'; @Component({ selector: 'div-wrapper', template: ` <div *ngIf="wrap; else unwrapped"> ...
Read more >Angular Wrapping Component With Ng Content (forked)
Editor Preview Both. Sign in. Project. Search. Settings. Switch to Light Theme. Enter Zen Mode. Project. Download Project. Info. Angular Wrapping Component ......
Read more >Content projection - Angular
This topic describes how to use content projection to create flexible, reusable components. To view or download the example code used in this...
Read more >Everything you need to know about ng-template, ng-content ...
Angular wraps the host element (to which the directive is applied) inside ... Components that are used in published libraries make use of ......
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 FreeTop 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
Top GitHub Comments
I expanded upon @mcelotti’s solution and successfully wrapped the accordion:
And the HTML:
I’ve used @moccaplusplus hack and it works also with ngb-tabset. But it’s a hack and therefore I’m testing the ngTemplateOutlet solution, here’s a demo: https://stackblitz.com/edit/angular-959kdu?file=app%2Fstepper.ts. Right now it’s working and I’m able to create my “wrapper” of ngb-tabset, but there might be some pitfalls