1、需求
打印文档,但是文档的打印,需要不同的格式和样式,所以模板和样式是动态的。
有关angular打印的组件不是很多,所以我们在网上找了
https://medium.com/@Idan_Co/angular-print-service-290651c721f9
网站,需要through the wall,该地址是告诉我们如何打印某一路由,我定义的是一个print路由,该路由定义的
prrint-document组件,现在的问题是,如何动态的给该组件绑定html和scss
,接下来的是核心,动态创建组件
@Component({
selector: 'app-print',
template: `<ng-container #vc></ng-container>`,
})
@ViewChild('vc', { read: ViewContainerRef, static: true }) public vc: ViewContainerRef;
public ngAfterViewInit(): void {
this._compileComponent();
}
public _compileComponent(): void {
const template = '<span>generated on the fly: </span><style>* {color: red;}</style>';
// 定义组件类及其