如何从 Angular 2 组件打开 Electron 对话框?

2023-12-31

我想单击一个按钮来打开组件中的文件夹对话框。这是我正在尝试做的事情:

HTML:

<div>
    <input class="u-full-width" placeholder="Folder" type="text" [(ngModel)]="folder">
    <button id="browse" class="button-primary" (click)="browse()">Browse</button>
    <input id="fileInput" type="file" style="display: none" />
</div>

组件.ts

// var remote = require('remote');
// var dialog = remote.require('dialog');

  folder: string;
  browse() {
    dialog.showOpenDialog({title: 'Select a folder', properties: ['openDirectory']}, (folderPath) => {
        if (folderPath === undefined){
            console.log("You didn't select a folder");
            return;
        }
        this.folder = folderPath;
    });
  }

那么,如何导入遥控器和对话框呢?


只需使用 es6 import 导入“remote”模块,然后你的 ts 文件就会像这样

import { remote } from 'electron';

folder: string;
browse() {
    remote.dialog.showOpenDialog({title: 'Select a folder', properties: ['openDirectory']}, (folderPath) => {
        if (folderPath === undefined){
            console.log("You didn't select a folder");
            return;
        }
        this.folder = folderPath;
    });
  }
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 Angular 2 组件打开 Electron 对话框? 的相关文章

随机推荐