angular - 使上下文可用于传递给 ng-content 的模板
问题描述
我在 app.module.ts 中有 2 个模块,即
- status.module.ts 和
- 表.模块.ts
以下是我的表格组件:
<ngx-datatable class="material"
[rows]="rows"
[columns]="columns"
[rowClass]="rowClass ? rowClass : null"
[columnMode]="'force'"
[headerHeight]="50"
[footerHeight]="50"
[rowHeight]="null"
[limit]="10"
[loadingIndicator]="loadingIndicator"
[groupRowsBy]="groupRowsBy"
[groupExpansionDefault]="groupExpansionDefault">
<!-- Group Header Template -->
<ngx-datatable-group-header *ngIf="groupRowsBy" >
<ng-template let-group="group" let-expanded="expanded" ngx-datatable-group-header-template>
<ng-content></ng-content>
</ng-template>
</ngx-datatable-group-header>
</ngx-datatable>
现在我需要从 status.component.html 为 ng-content(in table.component.html) 传递以下内容:
<span>
<button class="btn btn-link link" (click)="status.openStatus(group)">{{group.key}}</button>
</span>
这里的问题是在 status.component.html 中无法识别组,因为在 table.component.html 中声明了组
有没有办法让它工作?
解决方案
在状态组件中,创建模板引用变量 ( appTable
) 为:
<app-table #appTable>
<span>
<button class="btn btn-link link" (click)="status.openStatus(appTable.Group)">{{appTable.Group.key}}</button>
</span>
</app-table>
table.component 创建 setter 和 getter
_group: any;
set Group(value) {
this._group = value;
}
get Group() {
return this._group;
}
推荐阅读
- reactjs - 使用 Parcel 以自动方式在更改后编译 React 应用程序
- laravel - 无法使用 laravel 5.7 在 s3 存储桶中上传文件 - 参数 1 传递给 League\Flysystem\AwsS3v3\AwsS3Adapter:
- python - escpos python Windows 7的访问被拒绝(权限不足)
- webforms - 如何创建在 ASP.NET WEB FORMS 启动时运行的单例类(不依赖于用户登录)
- qt - QML 组合框元素的宽度
- json.net - 无法反序列化当前 JSON 数组 - Auth0 Management API Endpoint - 尽管使用在线 POCO 生成器
- c# - N个数的除数之和
- firebase - 设备未收到来自 FCM 的消息
- docker - Docker swarm,http 请求在覆盖网络上运行非常缓慢
- cypress - 赛普拉斯不允许可配置测试