[英]Electron + angularjs IPC mechanism
I am trying to use AngularJs inside Electron.我正在尝试在 Electron 中使用 AngularJs。 What i'm confused about is, the electron docs here suggest on using something like:
我感到困惑的是, 这里的电子文档建议使用以下内容:
// In renderer process (web page).
const ipcRenderer = require('electron').ipcRenderer;
console.log(ipcRenderer.sendSync('synchronous-message', 'ping')); // prints "pong"
ipcRenderer.on('asynchronous-reply', function(event, arg) {
console.log(arg); // prints "pong"
});
ipcRenderer.send('asynchronous-message', 'ping');
But since Angular is running inside the browser(webkit) I cannot essentially use
require
to get the ipcRenderer.但是由于 Angular 在浏览器(webkit)中运行,我基本上不能使用
require
来获取 ipcRenderer。
How would one overcome with this problem.如何克服这个问题。
You can use require
in electron - it extends the webkit API with this functionality.您可以在电子中使用
require
- 它使用此功能扩展了 webkit API。 Basically the whole NPM is at your disposal.基本上整个 NPM 都在你的掌控之中。 Well, some thing will not work, obviously, but
require
will.嗯,有些事情显然行不通,但
require
会。
It should work, but you need to add nodeIntegration它应该可以工作,但您需要添加nodeIntegration
mainWindow = new BrowserWindow({
width: 1024,
height: 632,
webPreferences: {
nodeIntegration: true
}
})
in the BrowserWindow constructor在 BrowserWindow 构造函数中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.