I am trying to print the simple data text using Angular and Qz-Tray. But everytime I try to Print the error is displayed:
qz-tray.js:35 ReferenceError: Sha256 is not defined
at Object.hash (qz-tray.js:408)
at WebSocket._qz.websocket.connection.sendData (qz-tray.js:184)
at qz-tray.js:280
at j (rsvp.min.js:1)
at new t (rsvp.min.js:1)
at Object.promise (qz-tray.js:395)
at Object.dataPromise (qz-tray.js:272)
at Object.print (qz-tray.js:805)
at PrinterService.push../src/app/shared/services/print.service.ts.PrinterService.printData (print.service.ts:46)
at FoddListComponent.push../src/app/layout/foodlist/foddlist.component.ts.FoddListComponent.createPdf (foddlist.component.ts:122)
I have included all the 3 .js files in index.html
Here is my index.html:
<head>
<meta charset="utf-8">
<title>ABC</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<script src="https://cdn.jsdelivr.net/npm/rsvp@4/dist/rsvp.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/js-sha256/0.9.0/sha256.js"></script>
<script type="text/javascript" src="./qz-tray.js"></script>
As @Bart has indicated, this means the sha256 is missing from your imports. He has provided a JavaScript (AngularJS) example because you have
angular
in your question tags however your example uses HTML tags. For completeness, here's the HTML requirements:Alternately, you can avoid RSVP by doing the following:
And, if running HTTPS with JavaScript running on a compatible browser you can avoid SHA256 by doing the following:
... but most people are just fine with @Bart's code snippet. Here's the full snippet from the QZ Tray wiki, AngularJS section: