I want to implement a scenario using angularjs in which user select a directory and after selection need to do some processing of each files in that directory.
Please find below code for the same HTML file:
<div ng-app="myApp" ng-controller="myCtrl">
<input id="folder" type="file" onchange="angular.element(this).scope().checkFiles(this.files)" webkitdirectory="" directory="" multiple="" />
</div>
Javascript code
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.checkFiles = function(files) {
console.log(files);
//add below line of code to trigger onchange event if user select same directory
angular.element(document.querySelector('#folder'))[0].value = null;
};
});
Plunker link https://plnkr.co/edit/lDhoShIVgCXLd33mPtbh?p=preview
The written code work for when selected directory has some file in it. But when I select empty directory it does triggers onchange event.
I tried alot but didn't got the root cause for this behavior.
One thing I noticed is that when i remove below line of code
//add below line of code to trigger onchange event if user select same directory
angular.element(document.querySelector('#folder'))[0].value = null;
and select a directory with some files and then select a empty directoy onchange event is getting triggred. But onchange event is not triggered if I directly select empty directory on first try.
Need to know why onchange event is not getting triggered for empty directory.
Note: Please try this code on chrome browser not supported for other browsers