首页 > 解决方案 > Angular 8:我可以在 window.open 中使用 ngx-barcode 吗?

问题描述

我可以在 window.open 中使用 ngx-barcode 吗?如何?

  modalPrint.document.write('<tr><td class="text-center"><ngx-barcode [bc-value]="value" [bc-display-value]="true"></ngx-barcode></td></tr>');

这是行不通的。或者我需要添加一个库的东西?

标签: angularbarcodewindow.open

解决方案


您应该以这种方式在您的角度组件中导入文档对象:

import { Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
So you can use it as the following :

@Injectable()
export class MyService {
  constructor(@Inject(DOCUMENT) private document: any) {
      document.write(your_code_here);
  }
}

推荐阅读