【问题标题】:AngularJS $promise not working in ngresourceAngularJS $promise 在 ngresource 中不起作用
【发布时间】:2018-01-29 13:33:14
【问题描述】:

对我来说,$promise.then() 不起作用。它抛出以下错误:

无法读取未定义的属性“then”

示例代码:

$scope.query = UserService.query();
$scope.query.$promise.then(function(data){
  console.log(data);
}); 

JSFiddle link

我该如何解决这个错误?

【问题讨论】:

  • 你使用的是什么版本的 angularjs

标签: angularjs


【解决方案1】:

使用 angularjs 1.6,它工作正常:

jsfiddle link

$scope.query = UserService.query();
$scope.query.$promise.then(function(data){
  console.log(data);
}); 

【讨论】: