1

这是我的 angularjs 代码,我在控制台上得到响应,无法以数组或 json 类型的形式获取它

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":"prashant@gmail.com","password":"weldone"}}));
});

控制台输出

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: "prashant@gmail.com"
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
4

1 回答 1

1

您需要使用成功和失败功能

user.login({"user": {"email":"prashant@gmail.com","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
    })
于 2013-09-03T14:18:39.120 回答