Is it possible to select by id in Angulars <ng-content>?

Viewed 5178

I'm playing around with Angular's (version 7) content projection. As far as I know, it's possible to select by attribute, class, and tag with the select attribute of <ng-content>.

I've also tried to select by id:

<ng-content select="#myID"></ng-content>

From:

<mycomponent>
   <div id="myid">
        Test
   </div>
</mycomponent>

But it doesn't seem to work.

Why does the selection of IDs not work?

1 Answers

I can't give a reason why you can't target an ID using the syntax like #myID, but you are able to target attributes on DOM nodes using a syntax like [attribute=value] (like you are able to in CSS selectors). Using this, you can then target for a specific ID attribute. In your case you would want to use the following:

<ng-content select="[id=myID]"></ng-content>
Related