2017-04-13 4 views
2

ボタンをクリックして、コンポーネント内のフォルダダイアログを開きます。ここで私が何をしようとしていますものです:角度2コンポーネントから電子ダイアログを開くにはどうすればいいですか?

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

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

、どのように私は、リモートインポートし、ダイアログのですか?

答えて

0

もうすぐです。レンダラで使用するドキュメント(https://github.com/electron/electron/blob/master/docs/api/dialog.md)によれば、const {dialog} = require('electron').remoteを実行する必要がありますので、最初のremote変数は必要ありません。

+0

おかげでそれを試すことができます。しかし、このコードを試してみると、ブラウザのコンソールで「Uncaught TypeError:fs.​​existsSyncはObjectの関数ではありません。 (vendor.bundle.js:72631)... 'と表示され、アプリは「読み込み中...」と表示されます。 – newman

+0

私は参照してください。メインプロセスで、ウィンドウを作成するときにノード統合を無効にしていますか?もしそうなら、上記のコードをpreloadスクリプトに置く必要があります。詳細については、この会話を参照してくださいhttps://github.com/electron/electron/issues/5113 –

+0

実際には、私は[https://github.com/onehungrymind/electrogram](https)]から別のサンプルコードベースに切り替えましたgithub.com/onehungrymind/electrogram)には、ダイアログを開くためのコードがあります。どうもありがとうございました! – newman

0

あなたはngx-electronライブラリとあなたの答えのための

import {ElectronService} from 'ngx-electron' 

export class DialogHelper { 

    private static alert = new ElectronService().remote.dialog; 
} 
関連する問題