2016-05-20 8 views
0

私は単純なファイルアップロードコードを使用しています。その示すエラー:AngularJsファイルアップロードのエラー表示

<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

この

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

をお試しください:

enter image description here

は、ここに私のコードです。

<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

働いていません!それでも同じエラーが出ます。 –

関連する問題