1

This is my angularjs code , I am getting response on console put not able to get it in array or json type form

angular.module('user', ['ngResource']).

config(function($httpProvider){
    $httpProvider.defaults.headers.common['Accept'] = "application/json"
})
    .factory('loginUser', function($resource){
    alert("hello amit we done it");
   var user=$resource('http://localhost/testtext/index.php/user/login', {}, {
           login: {method:'POST'}}

    );
        console.log(user.login({"user": {"email":"[email protected]","password":"weldone"}}));
});

console output

Resource {user: Object, $resolved: false, $then: function, $get: function, $save:    function…}
$resolved: true
$then: function (b,g){var j=e(),h=
User: Array[1]
0: Object
address: "Noida"
city: "Mathura"
clientid: "clint000000000000009"
country: "India"
email: "[email protected]"
flag: "0000000000"
fname: "Sushil"
id: "users000000000000041"
lname: "Kumar1"
password: "ee486c2fa50a03b53982cba45ef045c2"
reset_pw_token: ""
session: Object
auth_token: "a1054379e166a085f4f331074c36b6d7"
created_by: null
created_on: null
id: "usaut000000000000187"
scope: "a:11:  {i:0;s:19:"user/changepassword";i:1;s:11:"user/logout";i:2;s:12:"role/getrole";i:3;s:17:"ro  le/getprivilege";i:4;s:13:"category/save";i:5;s:13:"message/reply";i:6;s:16:"message/classify";i:7;s:12:"message/read";i:8;s:12:"message/list";i:9;s:12:"tag/messages";i:10;s:8:"tag/l ist";}"
updated_by: null
updated_on: "2013-09-03 19:30:52"
user_id: "users000000000000041"
__proto__: Object
state: "UP"
__proto__: Object
length: 1
__proto__: Array[0]
__proto__: Resource
2
  • You need to throw in a callback function, the first parameter in the callback is the responses data. Commented Sep 3, 2013 at 16:28
  • @ZackArgyle I do not get it, can you please elaborate it. Commented Sep 4, 2013 at 5:58

1 Answer 1

1

You need to use the success and failure function

user.login({"user": {"email":"[email protected]","password":"weldone"}},
function(data){
      console.log(data[0]) //or data.User[0] or data.user[0] depending upon on your json.
    },
function(error) {
    console.log(error)   // Error details
    })
Sign up to request clarification or add additional context in comments.

Comments

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.