angularjs file object is undefined -


int following code file object printing undefined why?

html

<input  type="file" name="issuefile" file-model="jsfile">  <a class="btn pull-right" ng-click="create()">create</a>   

controller

$scope.cancel = function () {   var fd = new formdata();   angular.foreach($scope.jsfile,function(file){                 fd.append('file',file);  });   fd.append('formdata',json.stringify(jsondata));             $http.post('admin/managecuisineadd',fd,{                 transformrequest:angular.identity,                  headers:{'content-type':undefined}              }).success(function(data){                  $scope.status=data;                  $scope.itemlist.push(data)                  $scope.message="new dish added successfully"   }); } 

as far know there no support input[type="file"] binding.

i use custom directive triggering change event , filling variable.

.directive('ngfileselect', [ '$parse', '$timeout', function($parse, $timeout) {     return function(scope, elem, attr) {             var fn = $parse(attr['ngfileselect']);             elem.bind('change', function(evt) {                 var files = [], filelist, i;                 filelist = evt.target.files;                 if (filelist != null) {                     (i = 0; < filelist.length; i++) {                         files.push(filelist.item(i));                     }                 }                 $timeout(function() {                     fn(scope, {                         $files : files,                         $event : evt                     });                 });             });         };     }]) 

in html use :

<input ng-file-select="onfileselect($files)" type="file"> 

and in controller :

$scope.onfileselect = function (files) {      console.info('files', files); }; 

Comments