This has been the most relevant thing I found: https://stackoverflow.com/a/11972028/110233
It seems to work fine when I only want to return one thing, but I'm unsure on how to return multiple things when the other things depend on the first thing.
Since that's kind of obtuse, here's a small example on what I'm currently doing:
window.EventRosterCtrl = ($scope, subevent) ->
$scope.subevent = subevent
EventRosterCtrl.resolve =
subevent: (SubEvent, $route) ->
deferred = $q.defer()
SubEvent.get {subevent_id: $route.current.pathParams.subevent_id}, (subevent) ->
deferred.resolve subevent
return deferred.promise
And here's an example of what I would want to do:
window.EventRosterCtrl = ($scope, subevent, addresses) ->
$scope.subevent = subevent
$scope.addresses = addresses
EventRosterCtrl.resolve =
subevent: (SubEvent, $route) ->
deferred = $q.defer()
SubEvent.get {subevent_id: $route.current.pathParams.subevent_id}, (subevent) ->
deferred.resolve subevent
return deferred.promise
addresses: (User) ->
deferred = $q.defer()
# how do you get subevent called first and how would you access it here?
for participant in subevent.participants
User.get {user_id: participant.user}, (user) ->
addresses[participant._id] = user.address
deferred.resolve addresses
return deferred.promise
Ok, so a you can't control it that way, but a work around that comes to mind (when one resolution is dependent on another finishing first) is just put everything in one object and resolve that. What ended up working best for me was making a service, but to follow my original example:
The EventRosterCtrl is only initialized when the subevent is ready, so the following should work:
you need to chain promisses using the .then()