1

我的问题类似于现有问题

我创建了一个服务(CoffeeScript)

dpmp.factory 'Keyword', ($resource) ->
  $resource '/keywords:id', {}, {query: {method: 'GET', isArray: false}}

得到正确的http响应,

{"title":"sysomos","subtitle":"Top keywords by mentions","unit":"times","data":[{"category":"partager","quantity":9753},{"category":"keyword1","quantity":6352},{"category":"keyword2","quantity":6311},{"category":"keyword3","quantity":2983},{"category":"keyword4","quantity":10}]}

我想从控制器中的资源中获取数据,即

$scope.keywords = Keyword.get()

但是这段代码不起作用。当我做

console.log($scope.keywords)

我得到的是函数,而不是数据。数据也已经存在,但我无法获取数据:

> Resource {$get: function, $save: function, $query: function, $remove: function, $delete: function}
  > data: Array[5]
    subtitle: "Top keywords by mentions"
    title: "sysomos"
    unit: "times"
  > __proto__: Resource

例如,console.log($scope.keywords.data)返回undefined.

有什么解决办法吗?或者你能告诉我这里发生了什么吗?

4

1 回答 1

1

试试下面

  Keyword.get(function(data){
 $scope.keywords=data
})
于 2013-08-13T10:14:43.133 回答