0

I have an array or json array

var Patient = {
        PatientID : $scope.PatientID,
        FirstName: $scope.FirstName,
        LastName: $scope.LastName,
        Disease: $scope.Disease,
        PhoneNo: $scope.PhoneNo
    };

I need to convert that Patient array to new FormData() by using loop

var patientData = new FormData();
for(var i = 0; i<=Patient.length; i++) {
    patientData.appent(Patient.Key,Patient.Value);
}

is this possible ?? or onsubmit, instad of creating Pating array can i directing get formdata as a FormData() or is there any another way to do this ??

2 Answers 2

1

You can do something like:

var patientData = new FormData();
angular.forEach(Patient, function (value, key) {
    patientData.append(key, value);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Don't mention it. Although I wouldn't edit your post the way you did it. Please be guided by proper casing and correct sentence structure, no doubling of punctuation marks.
0

Try this

var pateintData = new FormData();
for (var key in Patient) {
   patientData.append(key,Patient[key]);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.