我的要求:打印没有打印预览角度 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 未定义,如何更正?