是否可以在Angulars <ng-content>中通过id选择?

Rob*_*bin 3 angular angular7

我正在玩Angular的(版本7)内容投影。据我所知,可以按属性,类和带有select属性的标签进行选择<ng-content>

我也尝试通过ID选择:

<ng-content select="#myID"></ng-content>
Run Code Online (Sandbox Code Playgroud)

从:

<mycomponent>
   <div id="myid">
        Test
   </div>
</mycomponent>
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。

为什么选择ID无效?

Dan*_*pel 5

我无法给出为什么您不能使用语法来定位ID的原因#myID,但是您可以使用语法来[attribute=value](例如在CSS选择器中)将DOM节点上的属性作为目标。然后,您可以使用它指定特定的ID属性。在您的情况下,您将需要使用以下内容:

<ng-content select="[id=myID]"></ng-content>
Run Code Online (Sandbox Code Playgroud)