我正在尝试导入电子,以便从我的应用程序中打印发票
import { BrowserWindow } from 'electron'
但这是在抛出错误。
fs.existsSync不是一个函数
此外,我还试图从index.html页面中要求它,例如
<script>
var electron = require('electron');
</script>
但得到了
要求未定义
发布于 2018-10-23 12:46:21
到目前为止,我找到的最好的解决方案是使用ngx-电子
在你的电子里做:
const { ipcMain } = require('electron');
ipcMain.on('ping', (event, arg) => {
console.log('RECEIVED PING FROM ANGULAR APP', event, arg);
event.sender.sendSync('pong', 'yeah yeah yeah');
});
在你的角度应用程序中:
import { NgxElectronModule } from 'ngx-electron';
@NgModule({
declarations: [AppComponent],
imports: [
...
NgxElectronModule
],
...
})
在你的组件里:
import { ElectronService } from 'ngx-electron';
...
constructor(private _electronService: ElectronService)
...
if (this._electronService.isElectronApp) {
this._electronService.ipcRenderer.on('pong', (event, arg) => {
console.log(
'RECEIVED RESPONSE FROM ELECTRON TO ANGULAR APP',
event,
arg
);
});
}
...
this._electronService.ipcRenderer.send(
'ping',
'wow wow wow'
);
https://stackoverflow.com/questions/50286361
复制相似问题