I'm facing a challenge in my Angular.js application where I need to make three separate resource calls and then use the data together once all the requests are complete. Here are the three calls I need to make:
# Retrieve the curriculum
$scope.curriculum = CurriculumResource.get id: $routeParams.id
# Fetch the list of courses
$scope.courses = CourseResource.query()
# Get the array of groups
$scope.groups = GroupResource.query()
I've been trying to figure out how to execute additional logic after confirming that all the requests have finished. I attempted using both $watchGroup (as shown below) and $watchCollection, but neither seems to be functioning properly.
$scope.$watchGroup ['curriculum', 'courses', 'groups'], ->
# Despite expecting this to run whenever something changes in the above array,
# it only runs once
console.log 'Only runs once'
# Although eventually the values of the items in the following if statement become true,
# the condition never triggers when they are indeed true
if $scope.curriculum.groups and $scope.groups.length
console.log 'never gets here!'