Reputation: 719
My question is similar to an existing question.
I created a service (CoffeeScript)
dpmp.factory 'Keyword', ($resource) ->
$resource '/keywords:id', {}, {query: {method: 'GET', isArray: false}}
which gets the right http response,
{"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}]}
I want to get data out of the resource in the controller, i.e.
$scope.keywords = Keyword.get()
But this code does not work. When I do
console.log($scope.keywords)
I get functions, instead of the data, back. The data is also already there, but I cannot get the data out:
> 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
For example, console.log($scope.keywords.data)
returns undefined
.
Any solution? Or can you give me an idea what is going on here?
Upvotes: 1
Views: 1295
Reputation: 19037
Try the below
Keyword.get(function(data){
$scope.keywords=data
})
Upvotes: 1