AngularJS with ngResource: How to check exact response from server?

后端 未结 2 1057
礼貌的吻别
礼貌的吻别 2021-02-14 01:22

I have created an angular service to talk back to a simple REST server made in PHP. I can see that I am able to get a single record, list of all records, and add new records, ho

2条回答
  •  爱一瞬间的悲伤
    2021-02-14 01:46

    Hi i know its too late but may be helpful for others, The reason behind conversion of response to array is, angular-resource expects "data" property in response and after that it iterate over each items inside the "data" but if you sends an string inside the data property from server like this

    response = {
        data: true
        }
    

    then Angular-resource iterate over the "data" Object and makes an array of data so, the correct way is to send response is like this

    response = {
        data: {users: users} // Or any other property but not directly data
        }
    

    Thanks

提交回复
热议问题