I wonder if there is to avoid copying references to objects when you need to create a simple object with an array of built-in objects. The situation is this: I have a server that accepts JSON and applies some logic, and then stores the object in the database. let's say my form is for saving commands to the database. The server accepts the command as json. the team has an array of TeamMember objects, my form has a simple field for entering information about the member of the team member and adding it to the teamMembers array of the team. Now here is the problem when I add a team member to the list of arrays and want to add another team member when I enter the added element added in the field too! I know the reason
$scope.addTeamMember=function(teamMember){ $scope.team.teamMembers.push(teamMember); }
and this is because I put the same link in the teamMembers array, so I add the same object several times. to avoid this, I have to create a new team member object, copy all the properties of teamMember and add it to the array.
$scope.addTeamMember=function(teamMember){ var newTeamMember; $scope.team.teamMembers.push(newTeamMember); }
javascript angularjs
Adelin Jan 16 '13 at 14:15 2013-01-16 14:15
source share