Open KApoNG21 opened 3 years ago
Have you defined the socket?
Please refer to https://github.com/Ans0n-Ti0/esc-pos-encoder-ionic-demo/blob/main/EscPosDemo/src/app/tab3/tab3.page.ts
Have you defined the socket?
Please refer to https://github.com/Ans0n-Ti0/esc-pos-encoder-ionic-demo/blob/main/EscPosDemo/src/app/tab3/tab3.page.ts
Yes. I declare socket like these code.
import { BluetoothSerial } from '@ionic-native/bluetooth-serial/ngx'; import EscPosEncoder from 'esc-pos-encoder-ionic';
declare var BTPrinter: any; declare let window: any; declare var Socket: any;
POSPrint(){
const socket = new Socket();
/*
// socket receive bytecode, therefore we need to create a byte stream by using esc-pos-encoder-ionic
const encoder = new EscPosEncoder();
const result = encoder.initialize();
result
.align('center')
.newline()
.line('Congratulation, print success')
.line('IP : ' + this.printer.mIp)
.line('Port : ' + this.printer.mPort)
.newline()
.newline()
.newline()
.newline()
.newline()
.newline()
.cut();
const resultByte = result.encode();
// send byte code into the printer
socket.open(
this.printer.mIp,
this.printer.mPort,
() => {
socket.write(resultByte, () => {
socket.shutdownWrite();
});
},
(err) => {
console.error(err);
}
);
*/
}
If I comment like this. It can run normally.
@KApoNG21 someone has the same problem as you, have you declared socket?
https://github.com/NielsLeenheer/EscPosEncoder/issues/29#issuecomment-723554803
Hi, I try to use "esc-pos-encoder-ionic" NPM package in my Ionic project. When I try to open the page which use the service contains the imported library I have this error:
ERROR Error: Uncaught (in promise): ReferenceError: Cannot access 'HomePageModule' before initialization ReferenceError: Cannot access 'HomePageModule' before initialization
Related code:
import EscPosEncoder from 'esc-pos-encoder-ionic'; //---- createTicket(){ const encoder = new EscPosEncoder(); const result = encoder.initialize();
}