0

我正在使用 ng-resource 通过以下方式访问 API:

$resource('http://' + config.server.api + config.server.host + base_url + '/:id', {
    'id': '@id'
    },{
    'get' : {
        method : 'GET'
    },
    'add' : {
        method : 'PUT'
    },
    'update' : {
        method : 'POST'
    },
    'all' : {
        method  : 'GET',
        isArray : true
    },
    'del' : {
        method : 'DELETE'
    }
},{
    stripTrailingSlashes : false
});

我正在访问这样的资源:

apiService.Businesses.query(function(data){
  $scope.businesses = data;
});

但是,请求 URL 是:http: //API_URL.com/businesses/ :id

或者当我尝试使用“resource.get”时:

apiService.Businesses.get({id:1}, function(data){
  $scope.businesses = data;
});

请求 URL 为http://API_URL.com/businesses/:id/[object%20Object]


我显然在资源定义中遗漏了一些东西,但我无法弄清楚它是什么

4

1 回答 1

1

I still don't know what was the issue but switching the dependency seems to have solved it.

I'm using Bower and previously installed 'ng-resource'.

I tried to uninstall it and use 'angular-resource' instead and that did the trick.

于 2014-06-21T16:27:15.890 回答