user3072213
user3072213

Reputation: 23

For the existing object add a newly created object without modifying the other objects, here its loosig other properties

branchAccess.pendingList[i] object loosing other properties like it had.

branchAccess.pendingList[i].testMyAccessStatus its undefined after assigning newly added. can we use angular.copy or angular.clone to keep the object with its existing properties and also add a newly created object accessStatusDetails?

This is my code:

this.selectAll = function(branchAccess) {

        //checking if undefined
            var accessStatusDetailsAdd = {
                     accessStatusDetails : { accessStatus : "A" }
                }

            if(branchAccess.pendingList[i].accessStatusDetails == undefined){
                branchAccess.pendingList[i] = accessStatusDetailsAdd;
            }

        }   

Upvotes: 0

Views: 29

Answers (1)

Karol T
Karol T

Reputation: 1136

Check angular.extend() function

var object1 = {
  "color": "yellow",
}

var object2 = {
  "animal": "horse",
}

var mergedObject = angular.extend(object1, object2);

// mergedObject = {
//    "color": "yellow",
//    "animal": "horse"
// }

Upvotes: 1

Related Questions