1

I am trying to check the name of the file before the user hits submit. Can I get the filename like we get the content of the input field?

Something like:

<input name="posterTitle" type="text" ng-model="posterTitle">
{{posterTitle}}

Similarly in:

<input name="posterFileName" ng-model="posterFileName" type="file" />

2 Answers 2

1

Using Angularjs you might need to use an onchange event to bind the input name inside controller. see the example :

<input name="posterFileName" type="file" onchange="angular.element(this).scope().fileName(this)"/>

Inside controller

$scope.fileName= function(element) {
   $scope.$apply(function($scope) {
      $scope.posterTitle= element.files[0].name;
   });
};

Hope this will help.

Sign up to request clarification or add additional context in comments.

Comments

0

a couple of links I've found that may help a bit: http://api.jquery.com/file-selector/ jQuery: get the file name selected from <input type="file" />

for example, sing name or ID attribute:

$('input[type=file]').change(function(e){ $in=$(this); $in.next().html($in.val()); });

1 Comment

I was actually looking for an angular approach. I need to make comparisons with the filename in my angular controller.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.