0

我正在尝试将数据投影到几个 ng-contents,但是通过 ng-template。像这样的东西:

child.component.ts

<ng-content select="[first]"></ng-content>

<h3>seperator</h3>

<ng-content select="[second]"></ng-content>

app.component.ts

<child>
    <ng-container [ngTemplateOutlet]="template"></ng-container>
</child>

<ng-template #template>
    <h3 first> First </h3>
    <h3 second> Second </h3>
</ng-template>

问题是它不起作用。如果我不使用“选择”属性,它确实有效,但不会将 div 放置在正确的位置。

我已经尝试在子组件ContentChildren中手动使用和添加,TemplateRef但它仍然不会在正确的位置呈现 div。

Stackblitz 示例: https ://stackblitz.com/edit/angular-vdqmkl?file=src/app/child.component.ts

4

0 回答 0