ng-filedialog
v1.0.0
Published
angular file dialog for nwjs
Downloads
3
Readme
ng-fileDialog
angular file dialog for nw
What is it
This is a simple module for node-webkit applications written with AngularJS. It provides a service
called fileDialog
which allows you to show the user file dialogs like "save as" or "open file".
You can find more information in the
File dialogs
section of node-webkit's wiki.
This module allows you to
- Call "Save as" dialog
- Call "Open file" dialog
- Call "Open directory" dialog
- Provide filters by file types
- Allow user to select multiple files
- Specify a default name for the file
Dependencies
Usage
- Include the script into your HTML document after the AngularJS.
<script src="path/to/the/angular.js"></script>
<script src="path/to/the/ng-fileDialog.js"></script>
<script src="path/to/the/your-app-code.js"></script>
- Inject
ng-fileDialog
as dependency into your module.
var app = angular.module('app', ['ng-fileDialog']);
- Use the provided
fileDialog
service
app.controller('SomeCtrl', function($scope, fileDialog) {
$scope.saveFile = function() {
fileDialog.saveAs(function(filename) {
// your code
});
};
});
API
fileDialog.selectFile(callback, acceptTypes)
Opens the "open file" dialog, which allows the user to choose some file.
callback - function - function, which will be called if the user choose the file and clicks OK
button. Required interface: function(files)
.
acceptTypes - string/array - an array of accepted file types. See HTML5 specification.
fileDialog.selectFiles(callback, acceptTypes)
Opens the "open files" dialog, which allows the user to choose some file.
callback - function - function, which will be called if the user choose the file and clicks OK
button. Required interface: function(files)
.
acceptTypes - string/array - an array of accepted file types. See HTML5 specification.
fileDialog.selectDir(callback)
Opens the "open directory" dialog, which allows the user to choose some directory.
callback - function - function, which will be called if the user choose the directory and
clicks OK button. Required interface: function(file)
.
fileDialog.saveAs(callback, defaultFilename, acceptTypes)
Opens the "save as" dialog, which allows the user to input a name of the file to be saved.
callback - function - function, which will be called if the user enters a name of the file to
save and clicks OK button. Required interface: function(file)
.
defaultFilename - string - a default name of the file. Can be omitted by setting false.
acceptTypes - string/array - an array of accepted file types. See HTML5 specification.
fileDialog.open(options, callback)
Opens dialog.
options - Object - options.
multiple - *boolean * - a flag which the user to select multiple files. Default = false.
accept - string/array - an array of accepted file types.
webkitdirectory - boolean - WebKit show a directory select dialog. Default = false.
nwdirectory - boolean - node-webkit show a directory select dialog. Default = false.
nwworkingdir - string - default directory.
nwsaveas - boolean/string - open a 'save as' dialog, which lets user enter the path of a file. It's possible to select a non-existing file.
callback - function - function, which will be called if the user enters a name of the file to
save and clicks OK button. Required interface: function(file)
.
Important note
Please, keep in mind that there is no warranty that the callback function will be called each time you call any of the provided methods. If the user clicks the Cancel button the callback will not be called!