0

I am trying to process the response from REST Api but unable to do it as it is wrapped around a callback function using $resource in my angularjs application:

Service code:

apiService.factory("TestQuality", function ($resource) {
    var _url = "http://test.amat.com:8080/TestDashboard/TestQualityServlet";

    return $resource(_url, {}, {

        "query": {
            method: "GET",
            headers: {
                'Content-Type': 'application/json'
            }
        }
    });
});

Controller code:

..
.

var keyword = $scope.keyword ? $scope.keyword : '';
        var paramsObj = {};

        paramsObj['query'] = keyword;
        paramsObj['callback'] = jsonp_callback;

        $scope.testQualityPromise = TestQuality.query(paramsObj, function(response) {

            if (response && response.data.response.values && response.data.response.values.length > 0) {

                $scope.noData = false;

                $scope.testQualityData = response.data.response.values;

                $scope.testQualityTblData = new NgTableParams(
                {

                }, 
                { counts: [], dataset: $scope.testQualityTblData });

            } else {

                $scope.noData = true;

            }

        });

.. .

Response from REST API:

testqualitycallback({
    "data": {
        "response": [{
            "matches": 1,
            "ngroups": null,
            "values": [{
                "groupValue": "0010-02233",
                "result": [{
                    "afr_total_rejects_qty": 1,
                    "afr_systems_count": 149,
                    "afr_total_shipments_qty": 150.0,
                    "afr_percent": 0.6622516556291391
                }]
            }],
            "name": "test_number"
        }]
    }
})

Above code is not giving me the desired respone; need suggestions for handling this response to get the resultset shown to the view.

GOK
  • 2,338
  • 6
  • 34
  • 63
  • Debug and get it working with the [$http service](https://docs.angularjs.org/api/ng/service/$http) before doing it with $resource. – georgeawg Jun 23 '17 at 12:15
  • Can i get a solution or suggestion using $resource? – GOK Jun 25 '17 at 16:46
  • Under the hood, $resource uses $http. If you can't get it working with $http, you will never be able to get it working with $resource. – georgeawg Jun 25 '17 at 17:03
  • Do you have any experience on this over $http which you can suggest how to handle the wrapped callback? – GOK Jun 26 '17 at 05:33

0 Answers0