2

I have registration form and I have to pass the data in this format, till "LastName" I am able to send the data, but I am facing the issue to send the "Address" because there is one more array inside array. I tried lots of method search from google but not able to do.

{
       'Password':'125125', 
       'EmailAddress':'[email protected]',
       'FirstName':'David3',
       'LastName':'Hirst3',
       'Address':{
                  'Address1':'Unit 4',
                  'Address2':'1465 Gold Coast Hwy',
                  'State':'QLD',
                  'Suburb':'BBurleigh Heads',
                  'Postcode':'4220'
                }
    }

Please tell me how can I send this formdata with angularJs......

0

3 Answers 3

1

Here is the solution....

Here is my html code....

registration.html

 <div class="list list-inset">
                <label class="item item-input item-icon-left">
                    <i class="icon ion-android-note"></i>
                    <input type="text" placeholder="Address1*" name = "Address1"  ng-module = "formdata.Address.Address1">
                </label>
                <label class="item item-input item-icon-left">
                    <i class="icon ion-android-note"></i>
                    <input type="text" placeholder="Address2*" name = "Address2" ng-module = "formdata.Address.Address1">
                </label>
                <label class="item item-input item-icon-left">
                    <i class="icon ion-android-note"></i>
                    <input type="text" placeholder="State*" name = "State" ng-module = "formdata.Address.State">
                </label>
                <label class="item item-input item-icon-left">
                    <i class="icon ion-android-note"></i>
                    <input type="text" placeholder="Suburb*" name = "Suburb" ng-module = "formdata.Address.Suburb">
                </label>
                <label class="item item-input item-icon-left">
                    <i class="icon ion-ios7-location"></i>
                    <input type="text" placeholder="Post Code*" name = "PostCode" ng-module = "formdata.Address.PostCode">
                </label>

    <div>

controller.js

ctrl.controller('clinicCtrl', function($scope, $state, $window, api, $ionicLoading) {
    $scope.formData = {};
});

So, now I am getting the same format which one I want......

Sign up to request clarification or add additional context in comments.

Comments

0

You need to have array of objects.You you need to wrap the Address object with []

  var data = {
               'Password':'125125', 
               'EmailAddress':'[email protected]',
               'FirstName':'David3',
               'LastName':'Hirst3',
               'Address':[{
                          'Address1':'Unit 4',
                          'Address2':'1465 Gold Coast Hwy',
                          'State':'QLD',
                          'Suburb':'BBurleigh Heads',
                          'Postcode':'4220'
                        }]
            };

for Address

$scope.data = data.Address;

Fiddle

1 Comment

I have to send the this data to api with post method...so i am using like that $scope.formdata = {};
0

Try this:

{
       'Password':'125125', 
       'EmailAddress':'[email protected]',
       'FirstName':'David3',
       'LastName':'Hirst3',
       'Address':[{
                  'Address1':$scope.formData.Address1,
                  'Address2':$scope.formData.Address2,
                  'State':...,
                  'Suburb':...,
                  'Postcode':...
                }]
    }

Also I think you have a problem with your html

You should change ng-module to ng-model

From:

<input type="text" placeholder="Address1*" name = "Address1"  ng-module = "formdata.Address.Address1">

To:

<input type="text" placeholder="Address1*" name = "Address1"  ng-model = "formdata.Address.Address1">

This should work

1 Comment

No, I have api which is taken in this format only.....so I have to pass in this format...and I am using angularjs to pass the data by using "ng-module" directive...

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.