Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何在角5中导入电子_Node.js_Angular_Requirejs_Electron - Fatal编程技术网

Node.js 如何在角5中导入电子

Node.js 如何在角5中导入电子,node.js,angular,requirejs,electron,Node.js,Angular,Requirejs,Electron,我正在尝试从我的应用程序导入以打印发票 使用 但它正在抛出错误 fs.existsSync不是一个函数 此外,我还尝试从index.html页面中请求它,如 <script> var electron = require('electron'); </script> var electron=要求(“电子”); 但是 没有定义需求 到目前为止,我找到的最佳解决方案是使用 在您的电子设备中,只需执行以下操作: const { ipcMain }

我正在尝试从我的应用程序导入以打印发票 使用

但它正在抛出错误

fs.existsSync不是一个函数

此外,我还尝试从index.html页面中请求它,如

<script>  
        var electron = require('electron');  
</script>

var electron=要求(“电子”);
但是

没有定义需求


到目前为止,我找到的最佳解决方案是使用

在您的电子设备中,只需执行以下操作:

const { ipcMain } = require('electron');
ipcMain.on('ping', (event, arg) => {
    console.log('RECEIVED PING FROM ANGULAR APP', event, arg);
    event.sender.sendSync('pong', 'yeah yeah yeah');
});
在你的angular应用程序中:

import { NgxElectronModule } from 'ngx-electron';

@NgModule({
    declarations: [AppComponent],
    imports: [
        ...
        NgxElectronModule
    ],
    ...
})
在组件内部:

import { ElectronService } from 'ngx-electron';
...
constructor(private _electronService: ElectronService)
...
if (this._electronService.isElectronApp) {
            this._electronService.ipcRenderer.on('pong', (event, arg) => {
                console.log(
                    'RECEIVED RESPONSE FROM ELECTRON TO ANGULAR APP',
                    event,
                    arg
                );
            });
        }
...
this._electronService.ipcRenderer.send(
            'ping',
            'wow wow wow'
        );

走错了路。在electron内部使用“angular”,这是一个允许“类似浏览器的代码”在其中运行的环境。不要在“浏览器”中使用“it”。我想从我的应用程序打印发票,因此我已导入BrowserWindow。请尝试此操作。它可能有效npm install electron--save dev const{BrowserWindow}=require('electron')@MdAlamin我已经试过了,但是geeting
找不到name'require'。
error@sam你的客户端版本是什么??
import { ElectronService } from 'ngx-electron';
...
constructor(private _electronService: ElectronService)
...
if (this._electronService.isElectronApp) {
            this._electronService.ipcRenderer.on('pong', (event, arg) => {
                console.log(
                    'RECEIVED RESPONSE FROM ELECTRON TO ANGULAR APP',
                    event,
                    arg
                );
            });
        }
...
this._electronService.ipcRenderer.send(
            'ping',
            'wow wow wow'
        );