0

Hi i have tried creating a simple sign in service, but ended up with this error.

My service

foodModule.factory('Login', function($resource){
    return $resource('http://localhost:1337/User/', {}, {

    });
});

my fucntion

$scope.signIn=function(){
    console.log('Sign in function works');
    console.log($scope.user.signemail);
    console.log($scope.user.signpassword);
    $scope.signuser=Login.get({email:$scope.user.signemail,password:$scope.user.signpassword});
    console.log($scope.signuser);
}

Error:

Error: [$resource:badcfg] http://errors.angularjs.org/1.3.15/$resource/badcfg?p0=get&p1=object&p2=array

Am i doing anything wrong here? I hope i should mention the method properly, any idea on this error??

1

3 Answers 3

1

resource get should return a single object, but in your case, an array is being returned.

The problem could be that you are trying to do login using GET. Normally login is achieved using http POST. Most probably you should use Login.post instead of Login.get

Sign up to request clarification or add additional context in comments.

1 Comment

See the browser console what url is being hit. Is it the login url? Are the parameters passed correctly? If it is a post the data goes in body.
0

The parameters of $resources are as resource(url, paramDefaults, actions).

In first you already have url and blank paramDefaults are acceptable but in last parameters you need to specify explictly isArray: false .

So action can be like:-

'query': {method: 'GET', isArray: false }

Hope it helps :)

Comments

0

Make sure your $resource configuration matches the actual format of the data returned from the server.

For more information: https://docs.angularjs.org/api/ngResource/service/$resource

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.