我需要实现在Angle App中使用热敏打印机的功能不幸的是,我尝试没有成功

问题描述

我正在使用 ng-thermal-print ,但出现了一些错误。 依赖版本 安古拉:6 ng-thermal-print:0.1.5

package.json

"@agm/core": "1.0.0-beta.3","@angular/animations": "^6.1.7","@angular-devkit/build-angular": "~0.7.0","@angular/cli": "~6.1.2","@angular/compiler-cli": "^6.1.0","@angular/language-service": "^6.1.0","@angular/common": "^6.1.0","@angular/compiler": "^6.1.0","@angular/core": "6.1.0","@angular/fire": "^5.0.2","@angular/forms": "^6.1.0",

app.component.ts

import { Component,OnDestroy } from "@angular/core";
import { ApiService } from "../../services/api.service";
import { PrintService,UsbDriver,WebPrintDriver } from "ng-thermal-print";

@Component({
  selector: "app-dashboard",templateUrl: "./dashboard.component.html",})
export class DashboardComponent implements OnDestroy {
  status: boolean = false;
  usbPrintDriver: UsbDriver;
  webPrintDriver: WebPrintDriver;
  ip: string = "";

  public constructor(
    public api: ApiService,private printService: PrintService
  ) {
    this.usbPrintDriver = new UsbDriver();
    this.printService.isConnected.subscribe((result) => {
      this.status = result;
      if (result) {
        console.log("Connected to printer!!!");
      } else {
        console.log("Not connected to printer.");
      }
    });
  }

  requestUsb() {
    this.usbPrintDriver.requestUsb().subscribe((result) => {
      this.printService.setDriver(this.usbPrintDriver,"ESC/POS");
    });
  }

  connectToWebPrint() {
    this.webPrintDriver = new WebPrintDriver(this.ip);
    this.printService.setDriver(this.webPrintDriver,"WebPRNT");
  }

  print(data) {
    this.printService
      .init()
      .setBold(true)
      .writeLine("Hello World")
      .setBold(false)
      .feed(4)
      .cut("full")
      .flush();
  }

  ngOnDestroy() {}
}

app.component.html

<button class="btn btn-success">Print Order</button>

我遇到一些错误,例如 Object(...)不是函数 我已安装 @ types / w3c-web-usb 进行USB检测

我附上了错误图片。

error message

请帮助我

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...