Я создал angular 8 и электронное настольное приложение. Когда я посылаю сообщение из компонента root в основной. js файл электрона через ipcRenderer, он работает нормально. Но когда я отправляю сообщение из только что сгенерированного компонента в основной файл. js, он выдает ошибку «Невозможно прочитать свойство« отправить »из неопределенного».
Ниже приведена моя запись. компонент. html
<button (click)="write()">Click me</button>
мой файл write.component.ts
import { Component, OnInit } from '@angular/core';
import { IpcRenderer } from 'electron';
export class WriteComponent implements OnInit {
public ipcrenderer: IpcRenderer
ngOnInit() { }
write() {
this.ipcrenderer.on('message-to', (event, arg) => {
console.log("message-to" + arg)
});
this.ipcrenderer.send('message-from', 'hellooooooooooooo')
}
}
мой основной . js файл
const { app, BrowserWindow, ipcMain } = require('electron')
const url = require("url");
const path = require("path");
const http = require('http')
let mainWindow
function createWindow() {
mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
})
mainWindow.loadURL(
url.format({
pathname: path.join(__dirname, `/dist/index.html`),
protocol: "file:",
slashes: true
})
);
// Open the DevTools.
mainWindow.webContents.openDevTools()
mainWindow.on('closed', function () {
mainWindow = null
})
}
app.on('ready', createWindow)
app.on('window-all-closed', function () {
if (process.platform !== 'darwin') app.quit()
})
app.on('activate', function () {
if (mainWindow === null) createWindow()
})
ipcMain.on('message-from', (event, arg) => {
console.log(arg)
console.log("++++++++++++++++++++++++" + arg)
event.sender.send('message-to', "world");
})