从角度控制器使用文本框发送多个图像数据 [英] send multiple image data with textbox from angular controller
本文介绍了从角度控制器使用文本框发送多个图像数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将具有文本框值的多个图像数据发送到服务器端(PHP).我已经完成了多个图像上传,但是提交表单时我无法将数据发送到服务器端.我的查看代码在下面
i want to send multiple image data with textbox value to server side(PHP).i have done multiple image upload but i am not able to send my data to server side when submitting form.my view code is below
<form ng-submit="save()"><input type="file" file-upload multiple>
<div ng-repeat="step in files">
<img ng-src="{{step}}" />{{step.name}}
<input type="text" ng-model="comments">
</div>
<input type="submit"></form>
在我的控制器中
app.directive('fileUpload', function() {
return {
scope: true, //create a new scope
link: function(scope, el, attrs) {
el.bind('change', function(event) {
var files = event.target.files;
//iterate files since 'multiple' may be specified on the element
for (var i = 0; i < files.length; i++) {
//emit event upward
scope.$emit("fileSelected", {
file: files[i]
});
}
});
}
};
});
app.controller('mainCtrl', function($scope) {
$scope.files = [];
$scope.$on("fileSelected", function(event, args) {
var item = args;
$scope.files.push(item);
var reader = new FileReader();
reader.addEventListener("load", function() {
$scope.$apply(function() {
item.src = reader.result;
});
}, false);
if (item.file) {
reader.readAsDataURL(item.file);
}
});
});
当我单击提交按钮时,我想发送图像名称以及该图像的相应注释.我该如何通过api cal为php发送数据.在我的save()函数代码如下所示中
when i click submit button i want to send image name with corresponding comments for the image.how could i send the data through api cal for php.in my save() function code looks below
$scope.save = function()
{
console.log($scope.files)console.log($scope.comments)
}
推荐答案
您需要使用$http
服务将图像发送到服务器
you need to use the $http
service to send images to the server
$scope.save = function() {
var fd = new FormData();
fd.append('file', $scope.files);
$http.post('uploadUrl', fd, {
transformRequest: angular.identity,
headers: {
'Content-Type': undefined
}
})
.then(function(response) {})
.catch(function(response) {});
}
这篇关于从角度控制器使用文本框发送多个图像数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文