2013-05-08 75 views
0

我在使用AngularJS資源時遇到問題。AngularJS資源沒有正確地形成url

我有一個看起來像這樣的資源:

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 

我在做什麼錯?更具體地說,我應該怎麼做才能做對?

+0

你試過'$ resource('/:event'...)'? – akonsu 2013-05-08 15:09:41

+0

@akonsu實際上給了我'http:// localhost/inputData' – 2013-05-08 15:14:24

+0

如果刪除斜槓會發生什麼? – akonsu 2013-05-08 15:15:55

回答

1

嘗試$resource('./:event', ...)