电子到角度通信

问题描述 投票:0回答:1

I构建一个角应用,然后使用电子包装。 我的dir结构看起来像这样:
项目
| - 电子 --- |-main.js
----- | -Index.html(以及从WebApp/Dist复制的其他文件)
| -webapp(Angular App)
--- |-src
----- |-App
------- | - 服务

我尝试了过程间通信(

ipcMain

ipcRenderer
),但挂断了!
然后我知道
webcontent.executeJavascript();


我在Angular中提供了一项服务,该服务具有各种功能,例如

eventFromHost()

sendMessage()
我如何使用WebContent或任何其他方法从Electron的main.js调用此功能?

您应该使用

ipcMain
angular electron communication web-content
1个回答
5
投票
ipcRenderer

Angular:
ipcMain.send('foo', data);

电子:

ipcMain.on('foo', (event, data) => { // Do what you want with data. });
或使用

ipcRenderer

来使电子=>角度通信(
ipcMain
要从角到电子进行通信)。

如果您想查看一个现场示例,请在github上查看this main.jsfile

,以及与之通信的服务

import { Injectable } from '@angular/core'; import { ipcRenderer } from 'electron'; @Injectable({ providedIn: 'root' }) export class IpcService { private _ipc: typeof ipcRenderer | undefined; constructor() { this._ipc = window.require('electron').ipcRenderer; } send(message:string){ this._ipc?.send(message); } }

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.