是否可以在 Angular <ng-content> 中通过 id select?

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

我正在玩弄 Angular 的(版本 7)内容投影。据我所知,可以通过属性 select,class 和带有 <ng-content>.

属性的 select 标记

我也试过 select 通过 id:

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

发件人:

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

但是好像不行。

为什么 selectID 离子不起作用?

我无法给出为什么您不能使用像 #myID 这样的语法来定位 ID,但是您可以使用像 [=] 这样的语法来定位 DOM 节点上的属性12=](就像您可以在 CSS 选择器中那样)。使用它,您可以针对特定的 ID 属性进行定位。在您的情况下,您可能希望使用以下内容:

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