首页 > 解决方案 > 以完全不同的格式打印角度组件(视图)

问题描述

我的组件中有一个像这样的网格格式的进程列表

<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 以便以表格格式打印,但我无法让它工作,这是个好主意吗?或者有没有比这更好的解决方案?

标签: angularprintinghtml-tableprinting-web-page

解决方案


出现了用于打印的不同组件,使用 viewRef 调用它

    onPrint()
    {       
        this.viewRef = this.appDisplayService.rootViewContainer.createEmbeddedView(this.printerTemplate);       
    }

打印后需要将其从视图中删除

this.viewRef.destroy();

推荐阅读