angularzplqz-tray

Angular 6 with qz-tray


I have Angular CLI :7.3.4, Node:10.15.1. I have npm install qz-tray. I have my 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);
   }
 }

I have this error Could not find a declaration file for module 'qz-tray'. '../node_modules/qz-tray/qz-tray.js' implicitly has an 'any' type in the import statement. I followed the example given in: https://medium.com/@yehandjoe/angular-2-raw-printing-service-56614d358754 Any help is appreciated.I am trying to print raw text. I am open to any other libraries as well. Thank you


Solution

  • Quoting the 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));

    This is taken directly from the QZ Tray Angular Overrides documentation:

    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));