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

前端 未结 6 2154
失恋的感觉
失恋的感觉 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:09

    Just wanted to cross-post my adaptation of a solution Aleksander gave on another stackoverflow question: https://stackoverflow.com/a/16387288/626810:

    methodName: {method:'GET', url: "/some/location/returning/array", transformResponse: function (data) {return {list: angular.fromJson(data)} }}
    

    So when I call this function:

    var tempData = ResourceName.methodName(function(){
      console.log(tempData.list); // list will be the array in the expected format
    });
    

    Obviously this a little bulky if you need to GET arrays in multiple methods / resources, but it seems to work.

提交回复
热议问题