Angular POS Print Issue

别等时光非礼了梦想. 提交于 2019-12-11 11:37:18

问题


My requirement: Print without print preview angular 6

Only solution i found

Angular 2 Raw Printing Service I am using think link for Angular POS print

Do i have any other alternatives?

.ts code

 printInvoice() {
  console.log(this.printService.getPrinters());
  }

My Service code

import { Observable } from 'rxjs';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { Injectable } from '@angular/core';
import * as shajs from 'sha.js';
import * as qz from 'qz-tray';
**import * as RSVP from 'rsvp';**

@Injectable()
export class QzTrayService {
    constructor() { }

    errorHandler(error: any): Observable<any> {
        console.log('error handler');
        return Observable.throw(error);
    }

    // Get list of printers connected
    getPrinters(): Observable<string[]> {
        console.log(Observable
            .fromPromise(qz.websocket.connect()
                .then(() => qz.printers.find()))
            .map((printers: string[]) => printers) );
        return Observable
            .fromPromise(qz.websocket.connect()
            .then(() => qz.printers.find()))
            .map((printers: string[]) => printers)
            .catch(this.errorHandler);
    }

    // Get the SPECIFIC connected printer
    getPrinter(printerName: string): Observable<string> {
        return Observable
            .fromPromise(qz.websocket.connect().then(() => qz.printers.find(printerName)))
            .map((printer: string) => printer)
            .catch(this.errorHandler);
    }

    // Print data to chosen printer
    printData(printer: string, data: any): Observable<any> {
        // Create a default config for the found printer
        const config = qz.configs.create(printer);
        return Observable.fromPromise(qz.print(config, data))
            .map((anything: any) => anything)
            .catch(this.errorHandler);
    }

    // Disconnect QZ Tray from the browser
    removePrinter(): void {
        qz.websocket.disconnect();
    }
}

Error:

I get RSVP is not defined, how to correct this?


回答1:


Adding it in to that file will not make it available to other scripts.

You need to include it as a global script.

To do so, add the following into your index.html:

<head>
   <script src="../node_modules/rsvp/dist/rsvp.min.js"></script>
</head> 

Alternately, you can include it in angular.json in the scripts section



来源:https://stackoverflow.com/questions/52111087/angular-pos-print-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!