How do I expose a component's ViewChildren
to a parent component as ContentChildren
?
Say I have a component, MatSelect
, that looks for ContentChildren
like this:
@ContentChildren(MatOption, { descendants: true }) options: QueryList<MatOption>;
If I use this component as follows:
<mat-select>
<mat-option>
</mat-option>
</mat-select>
it will detect the mat-option
element as a content child.
Now if I create a component that generates these options, say OptionGeneratorComponent
, with a template as follows:
<mat-option *ngFor="let option of options" [value]="option">
{{option.viewValue}}
</mat-option>
Then I use this component as content for the previously mentioned MatSelect
component like this:
<mat-select>
<option-generator> <!-- option-generator instead of mat-option -->
</option-generator>
</mat-select>
the MatSelect
component doesn't detect the mat-option
elements generated by the OptionGenerator
element.
How do I make the MatSelect
component detect the MatOption
components I generated with OptionGeneratorComponent
as content children.
In this other demo I'm trying to find the Pane
elements generated by PaneGeneratorComponent
with the @ContentChildren
property in TabComponent
. It detects the Pane
elements that are hard coded but not the ones generated by the PaneGenerator
.
I have some more information and a demo about my exact use case in a question I posted earlier.