小编Muh*_*ili的帖子

使用 @ContentChildren() 访问每个 ng-template 名称

我编写了一个名为的组件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

angular-directive ng-template angular angular6

4
推荐指数
1
解决办法
2294
查看次数