AngularJS资源没有正确形成url

AngularJS resource not forming url correctly

本文关键字:url 资源 AngularJS      更新时间:2023-09-26

我在使用AngularJS资源时遇到了问题。

我有一个资源,看起来像这样:

loginModule.service('TestResource', function ($resource, $location) {
    var $scope = this;
    $scope.resource = $resource(window.location.path+'/:event', {event:'@event'});
    $scope.inputData = function(data1, data2, success){
        return $scope.resource.save({'event':'inputData'},{'data1':data1,'data2':data2},success);
    };
    return $scope;
});

是的,我试过使用:

//  $scope.resource = $resource($location.path()+'/:event');
//  $scope.resource = $resource(window.location.path+'/:event');
//  $scope.resource = $resource(':event');

Firebug报告这个尝试发送的地址是以下两个之一:

http://localhost/sandbox/test/undefined/inputData
http://localhost/sandbox/test/:event?event=inputData

我想要的是一个地址:

http://localhost/sandbox/test/inputData

我做错了什么?更具体地说,我应该做些什么来纠正它?

try $resource('./:event', ...)