2
votes

I have defined a custom method in my strongloop application, which returns the right datas when I test it through the Api explorer. I then generated the an angularjs service thanks to "lb-ng". When I send a request with this custom method through angular I get this error :

Error in resource configuration for action `list`. Expected response to contain an object but got an array (Request: GET http://**myip**/api/Questions)

The thing is it should call this address instead :

http://**myip**/api/Questions/4/0

It used to work at some point, before a regenerated an angular service with lb-ng

Here is the method registration in strongloop :

Question.remoteMethod(
'list', {
  http: {path: '/:lang/:start/', verb: 'get'},
  accepts: [
    {arg: 'lang', type: 'number'},
    {arg: 'start', type: 'number'}
  ],
  returns: {arg: 'questions', type: 'array'},
    description: ['Returns an array obj the latest added questions filters by language and categories']
}

)

And here is the calling test in angular in my homeController :

function getQuestions(langId, start) {
        Question.list(langId, start)
            .$promise
            .then(function(questionsList) {
                $scope.questions = questionsList.questions;
            }
        );
    }
    getQuestions(4, 0);

Do you have any idea why the method is not calling the address with arguments ?

2

2 Answers

0
votes

I am pretty sure that request parameters need to be on an object (as per the REST API use via explorer) as follows:

Question.list({lang:langId, start: start}).$promise.then(...)

I would also suggest generating the docular docs for the angular SDK as these help clarify things.

0
votes

In the service file that was generated look for the list method and add/set the isArray parameter as true, it should be something like this:

"list": {
  ...
  isArray: true,
  ...  
}