【发布时间】:2014-09-16 00:03:48
【问题描述】:
我有一个 Angular.js 应用程序,我需要调用三个不同的资源,一旦它们全部完成,就可以一起使用它们。我的三个电话如下。
# Get the curriculum
$scope.curriculum = CurriculumResource.get id: $routeParams.id
# Get the list of courses
$scope.courses = CourseResource.query()
# Get the list of groups
$scope.groups = GroupResource.query()
一旦我知道请求都已完成,我该如何执行更多逻辑。我试过使用下面显示的 $watchGroup 和 $watchCollection,但似乎都没有工作。
$scope.$watchGroup ['curriculum', 'courses', 'groups'], ->
# Shouldn't this run each time something in the above array changes?
console.log 'Only runs once'
# The values of the items in the below if statement eventually give a true result
# but the if statement never runs when they are true
if $scope.curriculum.groups and $scope.groups.length
console.log 'never gets here!'
【问题讨论】:
标签: javascript angularjs coffeescript