【问题标题】:Passing JSON data from Angular component to Electron main.ts将 JSON 数据从 Angular 组件传递到 Electron main.ts
【发布时间】:2020-09-22 15:18:51
【问题描述】:

正如标题所说,我正在开发一个 Angular 9 应用程序,它利用电子进行打包和一些 Node 功能。

我正在尝试将一些数据从我的一个组件发送到 Electron 的主进程,以便我可以利用 Node 的文件系统,但我在接收所述数据时遇到了问题。

这是我想要实现的(粗略)示例:

// on form.ts, should prepare the object and send it away
private ipc: IpcRenderer;
submit() {
  const json = {...json data...}
  this.ipc.send('save', json);
}

// on main.js, should receive and be able to print the object
ipcMain.on('save', (data) => {
  console.log(data);
});

该函数被成功调用,但我没有任何运气将 JSON 对象传递给它。 我该怎么做?

【问题讨论】:

    标签: angular electron


    【解决方案1】:

    监听器的第一个参数是事件,第二个参数是数据。试试这个:

    ipcMain.on('save', (event, data) => {
      console.log(data);
    });
    

    【讨论】:

      猜你喜欢
      • 2021-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-26
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2020-04-05
      相关资源
      最近更新 更多