我有一个独立运行的 angular 应用程序,我正在尝试创建一个电子应用程序,然后mainWindow.loadURL('http://localhost:4200/');它只是:它只是我的开发环境的本地主机,它不是真实的条件。
在电子中,我将 nodeIntegration 设置为 true,这允许我的 angular 应用程序访问 ipc。
const mainWindow = new BrowserWindow({
webPreferences: {
nodeIntegration: true,
}
});
Run Code Online (Sandbox Code Playgroud)
在 angular 我有我的乒乓功能:
public playPingPong() {
if(this._electronService.isElectronApp) {
console.log('Is electron.')
console.log(this._electronService.ipcRenderer);
let pong: any = this._electronService.ipcRenderer.sendSync('ping', 'ping');
console.log(pong);
}
}
Run Code Online (Sandbox Code Playgroud)
尽管在使用标题中的错误记录 ipcRenderer 后,应用程序出错了:
core.js:5845 ERROR Error: Unable to deserialize cloned data due to invalid or unsupported version.
at EventEmitter../lib/renderer/api/ipc-renderer.ts.ipcRenderer.sendSync (ipc-renderer.ts:13)
at ArcMapComponent.playPingPong (arc-map.component.ts:61)
at ArcMapComponent.ngOnInit (arc-map.component.ts:164)
at callHook (core.js:3909)
at callHooks (core.js:3873)
at executeInitAndCheckHooks (core.js:3814)
at refreshView …Run Code Online (Sandbox Code Playgroud)