角8电子无法读取未定义的属性“一次”

时间:2019-10-21 08:57:52

标签: angular electron

我为我的angular 8项目安装了电子设备,现在可以使用我的电子从我的angular 8项目构建桌面应用程序。这是我的项目的结构:

created

这是我的main.ts文件

 + dist
 + e2e
 + electron => which includes main.ts & tsconfig.json & dist, and inside dist is my main.js
 + node_modules
 + src

我想用电子从文件系统中读取文件,并创建了电子服务文件,然后从那里尝试调用 import { app, BrowserWindow, ipcMain } from 'electron' import * as path from 'path' import * as url from 'url' import * as fs from "fs"; let win: BrowserWindow app.on('ready', createWindow) app.on('activate', () => { if (win === null) { createWindow() } }); function createWindow() { win = new BrowserWindow({ fullscreen: true }) win.loadURL( url.format({ pathname: path.join(__dirname, `/panelfinal/index.html`), protocol: 'file:', slashes: true, }) ) win.webContents.openDevTools() win.on('closed', () => { win = null }) } ipcMain.on('getFiles', (event, arg) => { console.log(event + "this is event"); console.log(arg + " this is arg"); const files = fs.readdirSync(__dirname); console.log(files + " Electron"); win.webContents.send('getFilesResponse', files) }) 来访问文件系统。这是我的电子服务:

Ipc

当我在电子中调用 export class ElectronService { public ipc: IpcRenderer constructor(private snackBar: SnackbarService) { if ((<any>window).require) { try { this.ipc = (<any>window).require('electron').ipcRenderer } catch (error) { throw error } } else { console.warn('not for this platform') } } async getFiles(plaques: string[]) { new Promise<string[]>((resolve, reject) => { this.ipc.once("getFilesResponse", (event, arg) => { resolve(arg); }); this.ipc.send("getFiles", plaques); }); } } 方法时,出现此错误:

  

无法读取未定义的属性“一次”

有什么想法吗?

0 个答案:

没有答案