我正在使用简单的文件上传代码。它显示错误:
这是我的代码:
<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 :(得分:0)
试试这个
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]);
};