Angularjs $resource not working with an array returned from a REST API

前端 未结 6 2155
失恋的感觉
失恋的感觉 2020-12-06 05:15

I am trying to learn angularjs, and have hit a block in trying to databind to an array returned from a Rest API. I have a simple azure api returning an array of person objec

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-06 06:14

    I had similar problem and non of the answers quite worked for me, heres what i did:

        $resource("/", {}, {
           query: {
                method: 'GET',
                isArray: false,
                transformResponse: function (data, headers) {
                    //if no data return so no warnings
                    if (data == ''){
                        return;
                    }
    
                    return {data: $.extend({}, eval("{" + data + '}'))};
                }
            }
       });
    

    Uses jquery. Basically convert array to object so angularjs resource doesn't poop its pants.

提交回复
热议问题