I'm still learning Angular and am having some trouble accessing and using data across $resources. I have two api calls with two sets of data: wagers and users.
url:/users/me returns current username and id as an object
/wagers returns all wagers as an array. there is one field in wagers called userA, wagers?userA=(current user id) returns all the wagers whose userA=the current users id.
I am having trouble getting the (current user id) to dynamically pull in the current users id. My code is below:
//services
.factory('User', function($resource, $cookies){
return $resource('users/me', {}, {
query: {method:'GET', params:{}, isArray:false}
})
})
.factory('Wager', function($resource, User){
return $resource('wagers/', {}, {
query: {method:'GET', params:{}, isArray:true}
})
})
//controller
function WagerListCtrl($scope, $cookies, User, Wager){
$scope.users = User.query
$scope.wagers = Wager.query({"userA":user.id})
}