首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >电子IPC消息

电子IPC消息
EN

Stack Overflow用户
提问于 2020-07-04 15:45:29
回答 1查看 295关注 0票数 0

我正在用带有角度的电子制作一个应用程序。我想要实现的一个功能是在按下一个按钮之后,在整个过程开始之前,我想向用户弹出一个对话框消息框,向他显示一条消息。如果用户按了“是”或“否”,我会将结果从main.js返回给组件,并调用或不调用组件中存在的适当方法。

问题是角度给了我一个错误(不能设置属性的未定义),根据我认为的范围。

以下是我的尝试:

组件A:

代码语言:javascript
复制
//method of button
this.IpcService.send('navigateToMessageWindow', null);
this.IpcService.on('getDialogResault', function (event, arg) { 
   //here is the problem if i call another method it doesnt see it. and gives me an error.
});

Main.js

代码语言:javascript
复制
ipcMain.on('navigateToMessageWindow', (event, arg) => {
    const options = {
        type: 'question',
        buttons: ['Cancel', 'Yes', 'No'],
        defaultId: 2,
        title: 'Information',
        message: 'This procedure will take some minutes to complete. Are you sure you want to continue?',
    };

    dialog.showMessageBox(null, options).then((data) => {
        event.sender.send('getDialogResault', [data.response]);
    });
});

Ipc服务:

代码语言:javascript
复制
import { Injectable } from '@angular/core';
import { ElectronService } from 'ngx-electron';

@Injectable({
    providedIn: 'root'
 })

export class IpcService {

    constructor(private _electronService: ElectronService) { }

    public on(channel: string, listener: Function): void {
        this._electronService.ipcRenderer.on(channel, (evt, args) => listener(evt, args));
    }

    public send(channel: string, ...args): void {
        this._electronService.ipcRenderer.send(channel, args);
    }
}
EN

回答 1

Stack Overflow用户

发布于 2020-07-07 22:05:09

使用上述箭头函数,解决了问题。

代码语言:javascript
复制
this.IpcService.send('navigateToMessageWindow', null);
        this.IpcService.on('getDialogResault', (event, arg) => {
 });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62731148

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档