Sabab Zulfiker

Sabab Zulfiker

  • NA
  • 85
  • 25.5k

Uploading two files by two file input in Angular JS

Apr 24 2018 6:26 AM
I am checking extension of files , using angular js , my html code is:
 
<input type="file" name="file" onchange=" angular.element(this).scope().selectFileforUpload(this.files) " required/>
<input type="button" value="Upload File" ng-click="SaveFile()"/>
 
and angular controller code is :
 
$scope.verifiedFileType = function (file) {
var fileName = file.name;
var extension = (fileName.substring(fileName.lastIndexOf('.'), fileName.length)).toLowerCase();
if (extension === ".pdf") {
return true;
}
else {
return false;
}
};
$scope.click = function () {
if ($scope.verifiedFileType($scope.SelectedFileForUpload)) {
alert("Yes");
} else {
alert("No");
}
}
 
This works fine. But I want to check the extension of two files of two separete file inputs. I have tried this:
 
<input type="file" name="file" onchange=" angular.element(this).scope().selectFileforUpload(this.files) " required/>
<input type="file" name="file2" onchange=" angular.element(this).scope().selectFileforUpload(this.files) " required/>
<input type="button" value="Upload File" ng-click="SaveFile()"/>
 
 
 
$scope.click = function () {
if ($scope.verifiedFileType($scope.SelectedFileForUpload[0]) && $scope.verifiedFileType($scope.SelectedFileForUpload[1])) {
alert("Yes");
} else {
alert("No");
}
}
But this code doesn't run. What should I do?