Angular 6个带qz托盘

Angular 6 with qz-tray

我有 Angular CLI:7.3.4,Node:10.15.1。我有 npm install qz-tray。我有我的 service.ts:

import { Injectable } from '@angular/core';
import 'rxjs/add/operator/map';
import { from , Observable } from 'rxjs';
import * as qz from 'qz-tray';
import { sha256 } from 'js-sha256';

declare var qz: any;
    @Injectable({
      providedIn: 'root'
    })
export class PrintingService {
   constructor() { }
   errorHandler(error: any): Observable<any> {
    return Observable.throw(error);
   }
 }

我遇到此错误无法找到模块 'qz-tray' 的声明文件。 '../node_modules/qz-tray/qz-tray.js' 在 import 语句中隐含了一个 'any' 类型。 我按照以下给出的例子: https://medium.com/@yehandjoe/angular-2-raw-printing-service-56614d358754 任何帮助都是 appreciated.I 我正在尝试打印原始文本。我也对任何其他图书馆开放。谢谢

引用OP:

Figured out ..I wasn't over riding the sha256.. once I added this.. all good.. qz.api.setSha256Type(data => sha256(data)); qz.api.setPromiseType(resolver => new Promise(resolver));

这直接取自 QZ 托盘 Angular Overrides 文档:

import * as qz from 'qz-tray';
import { sha256 } from 'js-sha256';

qz.api.setSha256Type(data => sha256(data));
// ^========== HERE ==========^

qz.api.setPromiseType(resolver => new Promise(resolver));

qz.websocket.connect()
 .then(qz.printers.getDefault)
 .then(printer => console.log("The default printer is: " + printer))
 .then(qz.websocket.disconnect)
 .catch(err => console.error(err));