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" />
magnum
  • 47
  • 6

2 Answers2

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.

Nufayl
  • 464
  • 6
  • 6
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()); });

Community
  • 1
  • 1
bob.mazzo
  • 5,183
  • 23
  • 80
  • 149
  • I was actually looking for an angular approach. I need to make comparisons with the filename in my angular controller. – magnum Feb 28 '14 at 19:58