【问题标题】:How to pass template from 1 component to another如何将模板从一个组件传递到另一个组件
【发布时间】:2018-11-10 21:30:40
【问题描述】:

app.module.ts 是根模块。

它有 2 个子模块 - 1. table.module.ts 和 2. status.module.ts

Table 组件是 ngx-datatable 的包装器。我需要将下面的模板从 status.component.ts 传递给 table.component.ts:

<ngx-datatable-group-header *ngIf="groupRowsBy" >
    <ng-template let-group="group" let-expanded="expanded" ngx-datatable-group-header-template>
        <span>
            <button (click)="showStatus(group)">{{group.key}}</button>
        </span>
    </ng-template>
</ngx-datatable-group-header>

我尝试在 table.component.ts 中使用&lt;ng-content&gt;&lt;/ng-content&gt; 并从 status.component.ts 传递上面的模板

但它不起作用。谁能建议如何通过这个模板?

提前致谢

【问题讨论】:

    标签: angular typescript angular2-template siblings


    【解决方案1】:

    如果您尝试将状态组件的模板传递给平板电脑组件,您可以声明您的平板电脑组件

    您将像这样声明您的平板电脑组件 html 您可以将所有平板电脑模板放在这里,也可以在任何您想插入状态模板的地方放

    设置好平板电脑组件后,您可以像这样将状态模板传递给它

    <tablet-component></tablet-component>
    

    在这里,您将把状态模板放在平板组件选项卡中

    【讨论】:

    • 我在下面看不到任何内容,很可能您可能错过了格式
    猜你喜欢
    • 2018-03-07
    • 2020-12-30
    • 1970-01-01
    • 2023-01-30
    • 2021-10-31
    • 2019-11-06
    • 1970-01-01
    相关资源
    最近更新 更多