angular - 以完全不同的格式打印角度组件(视图)
问题描述
我的组件中有一个像这样的网格格式的进程列表
<grid #grid [dataSourceCallback]="getList" type="simple">
<ng-template let-process="row">
<ws-process-item [process]="process" type="full"></ws-process-item>
</ng-template>
</grid>
但我需要以表格格式打印此列表,如下所示
<ng-template let-process="row">
<tr class="d-flex">
<th class="col-1">{{ process.id }}</th>
<th class="col-2">{{ process.title }}</th>
<th class="col-2">{{ process.description }}</th>
</tr>
</ng-template>
我试图隐藏下面的代码并在打印时显示它,但这不是一个强大的解决方案。有人建议我创建临时 viewref 以便以表格格式打印,但我无法让它工作,这是个好主意吗?或者有没有比这更好的解决方案?
解决方案
出现了用于打印的不同组件,使用 viewRef 调用它
onPrint()
{
this.viewRef = this.appDisplayService.rootViewContainer.createEmbeddedView(this.printerTemplate);
}
打印后需要将其从视图中删除
this.viewRef.destroy();
推荐阅读
- mysql - MYSQL - 在 INSERT 语句中使用函数
- llvm - 如何查找或生成示例 LLVM 项目?
- r - model.frame.default 中的错误(公式 = SHOT_MADE_FLAG ~ ti(LOC_X) + :使用 R gam 的变量 'ti(LOC_X)' 的类型(列表)无效
- php - Laravel 关系急切加载限制所有结果而不是特定于模型
- mongodb - 用大量 objectIds 查询数组的最佳方法是什么
- react-native - 如何正确更改 React Native Top Navigation 中的 indicatorStyle 的宽度?
- swift - 'Album.Type' 不能转换为 '() -> Album'
- python - python 3中的多处理和多线程
- r - 在 R txt 文件中查找和替换数字
- ruby-on-rails - Ubuntu + Unicorn:您必须使用 Bundler 2 或更高版本与此锁定文件。(Bundler::LockfileError)