0

I have a set of array and object that look like this

`

var PaymentContent = "Payments":
     [{
        "Details": {
                    "PaymentType": "CreditCard",
                    "Amount": $scope.total,
                    "CCNAME": $scope.Form.CreditCard.FullName,
                      }
      }]
Payments: Array[1]
0:Object
 Details: Object
 Amount: 5.99
 CCNAME: null
 PaymentType: "CreditCard"`

Now, how can i update that set of objects and array using angularjs? desired output :

Payments: Array[1] 0:Object Details: Object Amount: 5.99 CCNAME: null PaymentType: "CreditCard" LastPayment: "04/11/2011"

Notice the lastpayment field.

Here is my code

var paymentDetails = {LastPayment : '04/11/2011', LastSignOn : '04/11/2011'} fields = angular.extend({}, PaymentContent , paymentDetails);

Thanks!

3
  • You should show your complete object interaction code. BTW adding a property to existing object is just like assigning one like a.LastPayment = "sample"; Commented Sep 22, 2015 at 4:31
  • 3
    you could easily add LastPayment in payment array by Payments[0].LastPayment = '04/11/2011' Commented Sep 22, 2015 at 4:32
  • @Alex the thing you are talking is not reproduceable..could you please try reproduce it here jsfiddle.net/78y9T/73 Commented Sep 22, 2015 at 4:50

2 Answers 2

2

You are setting an empty object as destination. This new object will receive the properties and values of the other 2 objects...without changing those other 2 source objects

If you want the array object to receive the updates remove the first argument ( the empty object)

angular.extend( fields.Payments[0].Details, paymentDetails);

This will update fields.Payments[0].Details with all of the properties and values in paymentDetails

Demo Fiddle

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

Comments

2

You can directly write below code:

Payments[0].LastPayment = "04/11/2011";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.