通过在angularJs中使用ng-resource来获取数据

时间:2015-06-06 14:15:39

标签: javascript json angularjs api

我正在尝试使用ng-resource中的angularjs从API查询模块列表。

配置,

var classifiedApp = angular.module('classifiedApp', ['ngRoute', 'ngResource']);

服务,

classifiedApp.factory('Module', ['$resource', function ($resource) {
    return $resource('api/0.1.0/modules/:id'); // Note the full endpoint address
}]);

在控制器中,

 Module.query(function (response) {
                    $scope.modules = response;
                    console.info($scope.modules)
                });

API返回正确的JSON对象,但在$scope.modules中包含以下josn,

 [Resource { id=1,  title="Mobiles & Tablets",  categories=[3],  more...}, Resource { id=2,  title="Vehicles",  categories=[7],  more...}, Resource { id=3,  title="Electronics & Computers",  categories=[0],  more...}]

如何获得纯API响应JSON

0 个答案:

没有答案