I have the following AngularJS model:
$scope.Model = {
Users : [{
UserId: '',
FirstName: '',
LastName: ''
}],
Products :[{
ProductId: '',
Price: ''
}]
};
If I populate this array with N users, and one user has id=1
, how can I update that specific user (with id=1
) the property LastName
?
So for example if I will get a new AngularJS model:
$scope.UserToUpdate ={
UserId: 1,
LastName: "Smith"
};
I want to loop through the $scope.Model
array and update the user with id=1
but only the FirstName
property.
P.S. I don't know at what position the target user object in the array it is so basically can be at $scope.Model.Users[0]
or $scope.Model.Users[1]
or $scope.Model.Users[10]
or at $scope.Model.Users[N]
...