如何从角度2组件打开电子对话框? [英] How to open an Electron dialog from angular 2 component?

查看:60
本文介绍了如何从角度2组件打开电子对话框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to click a button to open folder dialog in my component. Here is what I am trying to do:

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>

component.ts

component.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;
    });
  }

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

So, how do I import remote and dialog?

推荐答案

只需使用es6 import导入远程"模块,然后您的ts文件就会像

Just import the "remote" module using es6 import,and then your ts file will be like

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;
    });
  }

这篇关于如何从角度2组件打开电子对话框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆