I need to combine two arrays together. In the this code block I'm trying to get each user row from the foo array and make it into a new array.
UserService.GetUserFoo(id)
.success(function (data) {
data = angular.fromJson(data); //[{id:1, u_id:1, foo:"a"}{id:2, u_id:2, foo:"b"}]
angular.forEach(data, function(user){
getUser(user.u_id) }); //FUNCTION CALL
}).
error(function(error) {
//do something
});
In this code block, the getUser function is called in the GetUserFoo service to populate a new array called $scope.users
$scope.users = []; //[{id:1, name:"Ed"},{id:2, name:"Jim"}]
var getUser = function(id) {
UserService.GetUserById(id)
.success(function (data) {
data = angular.fromJson(data);
$scope.users.push(data); //
}).error(function(error) {
//do something
});
};
QUESTION --> How do insert each foo field into each corresponding $scope.users object so that in my view i can have something like this
//[{id:1, name:"Ed", foo:"a"}{id:2, name:"Jim", foo:"b"}]
<li ng-repeat="user in users">
<h2>{{user.name}}</h2>
<p>{{user.foo}}</p>
</li>