I am trying to pass a file from html view to angular controller, for this I am using ng-file-select in the view. My view code looks like:
- <div ng-controller="fileController">
- <input type="file" ng-model="fibQuestion.fibContentLanguage.colUploadPaperUrl" name="PaperDocUrl" ng-file-select="onPaperFileSelect($files)" onclick="this.value = null" id="forPracticalTestPaper" />
- <div>
- <input type="button" id="save" class="btn btn-success" value="Save" ng-click="PaperFileProcessing()" />
- </div>
- </div>
But here, ng-file-select="onPaperFileSelect($files)" cannot passing the file to the controllers. The controller code is :
- app.controller('fileController',function($scope) {
- $scope.message = "From Controller";
- $scope.onPaperFileSelect = function ($files) {
- if ($scope.verifiedFileType($files[0].name, 'paper')) {
- $scope.saveFileLoacation = '~/UploadedFiles/PracticalTestPaperFiles/';
- $scope.yesDisable = false;
- $scope.uploadedPaper = $files;
- $('#upload-paper-file-info').text($files[0].name);
- $scope.showPaperDeleteButton = true;
- } };
- $scope.verifiedFileType = function (fileName, fileType) {
- var extension = (fileName.substring(fileName.lastIndexOf('.'), fileName.length)).toLowerCase();
- if (extension == ".pdf") {return true;}
- else {alert("file extension not valid for " + fileType + ". available extensions are pdf.");
- angular.element("input[type='file']").val(null);
- return false;
- } };
- $scope.PaperFileProcessing = function () {
- $scope.upload = [];
- $scope.yesDisable = true;
- var fileBank = $scope.uploadedPaper;
- console.log(fileBank);
- var status = false;
- var i = fileBank.length;
- console.log(i);
- };
- });
When , I press the save button, that calls the function PaperFileProcessing(), but then, var fileBank = $scope.uploadedPaper; is showing undefined.