2016-05-20 4 views
0

Я использую простой код для загрузки файлов. Его показ ошибка:Ошибка загрузки файла AngularJs

enter image description here

Вот мой код:

<input type="file" name="student_image" onchange="angular.element(this).scope().uploadFile(this.files)" ng-model="formData.studentImage" id="student_image"> 

$scope.uploadFile = function (files) { 
     var form_data = new FormData(); 
     form_data.append("file", files[0]); 
     $http.post('process.php', form_data, { 
      transformRequest: angular.identity, 
      headers: {'Content-Type': undefined} 
     }).success(function (data) { 
      if (data == "failed") { 
       // if not successful, bind errors to error variables 
       $scope.errorFinal = "Failed"; 
      } else { 
       $scope.formData.image_name = data; 
      } 
     }).error('failed'); 
    }; 

ответ

0

Try This

angular.element(this).scope().uploadFile(this); 

.

<input type="file" name="student_image" onchange="angular.element(this).scope().uploadFile(this)" ng-model="formData.studentImage" id="student_image"> 

JS

$scope.uploadFile = function(data){ 
    console.log(data.files[0]); 
}; 
+0

Не работает! все еще выдавая ту же ошибку. –

Смежные вопросы