सरल शब्दों में
Html में - केवल नीचे दिया गया कोड जोड़ें
<form name="upload" class="form" data-ng-submit="addFile()">
<input type="file" name="file" multiple
onchange="angular.element(this).scope().uploadedFile(this)" />
<button type="submit">Upload </button>
</form>
नियंत्रक में - यह फ़ंक्शन तब कहा जाता है जब आप "अपलोड फ़ाइल बटन" पर क्लिक करते हैं। यह फ़ाइल अपलोड करेगा। आप इसे सांत्वना दे सकते हैं।
$scope.uploadedFile = function(element) {
$scope.$apply(function($scope) {
$scope.files = element.files;
});
}
नियंत्रकों में और जोड़ें - नीचे कोड फ़ंक्शन में जोड़ें। यह फ़ंक्शन तब कहा जाता है जब आप बटन पर क्लिक करते हैं जो "एपीटी (POST) मार" का उपयोग किया जाता है । यह फ़ाइल (जो अपलोड की गई) और फॉर्म-डेटा को बैकएंड पर भेजेगा।
var url = httpURL + "/reporttojson"
var files=$scope.files;
for ( var i = 0; i < files.length; i++)
{
var fd = new FormData();
angular.forEach(files,function(file){
fd.append('file',file);
});
var data ={
msg : message,
sub : sub,
sendMail: sendMail,
selectUsersAcknowledge:false
};
fd.append("data", JSON.stringify(data));
$http.post(url, fd, {
withCredentials : false,
headers : {
'Content-Type' : undefined
},
transformRequest : angular.identity
}).success(function(data)
{
toastr.success("Notification sent successfully","",{timeOut: 2000});
$scope.removereport()
$timeout(function() {
location.reload();
}, 1000);
}).error(function(data)
{
toastr.success("Error in Sending Notification","",{timeOut: 2000});
$scope.removereport()
});
}
इस स्थिति में .. मैंने प्रपत्र डेटा के रूप में कोड नीचे जोड़ा
var data ={
msg : message,
sub : sub,
sendMail: sendMail,
selectUsersAcknowledge:false
};