1

I had a $resource that servers two files, names.js and birthday.js:

// names.js
{
  name: John,
  name: Mary,
}

// birthday.js
{
  John: 28,
  Mary: 28
}

It works great in my controller. But I couldn't run ng-repeat on it. So I converted the data to a format that was used in the ng-repeat docs:

// friends.js
friends = [{name:'John', age:25}, {name:'Mary', age:28}];

But now my provider for friends.js returns an array of characters (not very useful) or an object of characters. How can I make it so that my provider returns a useful format of the data?

The query in the service is:

friends: $resource('data/friends.js', {}, {
  query: {method: 'GET', params: {}, isArray: true[or false]}
})

In short, how do you use a $resource to provide friends.js?

1 Answer 1

0

How do you query your $resource?

The get method is expecting an object while the query method is expecting an array.

This is the default methods available on a $resource :

{ 'get':    {method:'GET'},
  'save':   {method:'POST'},
  'query':  {method:'GET', isArray:true},
  'remove': {method:'DELETE'},
  'delete': {method:'DELETE'} };

More info available here :

AngularJS resource documentation

1
  • I've updated my question to include the query. Regardless of setting isArray, the service provides an Object / or Array of characters. I'd like to use this data in the controller, so an object/array of character would be useless for me. I'd like to keep friends.js as the data because I'd like to run the ng-repeat directive on this dataset.
    – hzhu
    Commented Jul 29, 2013 at 1:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.