TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sabab Zulfiker
NA
85
25.6k
File not Passing on ng-file-select in Angular JS
Apr 23 2018 6:02 AM
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.
Reply
Answers (
0
)
Server side paging in angular datatable .
Navigation to a new page in angular 5 on ONFocus