1

我的要求:打印没有打印预览角度 6

我找到的唯一解决方案

Angular 2 Raw Printing Service 我正在使用 think link 进行 Angular POS 打印

我还有其他选择吗?

.ts 代码

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

我的服务代码

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

错误:

我得到 RSVP 未定义,如何更正?

在此处输入图像描述

4

1 回答 1

2

将其添加到该文件不会使其可用于其他脚本。

您需要将其作为全局脚本包含在内。

为此,请将以下内容添加到您的 index.html 中:

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

或者,您可以将其包含在angular.json脚本部分

于 2018-08-31T08:32:02.157 回答