Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ng-content to select base class

Suppose I have a component Parent that content projects Child components as follows. In this case, Child is an abstract base class that is extended by components ChildA and ChildB. Here's an example use cased in a user's template:

<parent>
  <child-a></child-a> // or child-b
</parent>

In the Parent's template I want to use <ng-content> to content project the Child component. However, I want to be able to use <ng-content> and somehow select either the <child-a> or <child-b>, something like:

<ng-content select="child-a | child-b"></ng-content>

Is there a way to do this?

like image 667
sir_thursday Avatar asked Oct 29 '25 07:10

sir_thursday


1 Answers

You can do this using a comma separated list like this:

<ng-content select="child-a,child-b"></ng-content>
like image 54
jo_va Avatar answered Oct 31 '25 01:10

jo_va



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!