我编写了一个名为的组件my-component,并在里面添加了一些组件ng-template,并为每个组件命名,#如下所示:
<my-component>
<ng-template #one>
1st format
</ng-template>
<ng-template #two>
2nd template
</ng-template>
<ng-template #three>
3rd template
</ng-template>
</my-component>
Run Code Online (Sandbox Code Playgroud)
在 的声明中MyComponent,我曾经@ContentChildren(TemplateRef)访问过这三个模板。
现在我需要以某种方式在内部访问这些模板的名称(one、、),但我不知道如何。这是代码:示例代码twothreeMyComponent