AngularJS资源没有正确形成url

时间:2013-05-08 14:55:18

标签: javascript angularjs

我在使用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

我做错了什么?更具体地说,我该怎么做才能做到正确?

1 个答案:

答案 0 :(得分:1)

尝试$resource('./:event', ...)