2013-12-18 14 views
1

我有一個簡單的ASP.NET Web API 2服務。我是Angular的新手,但我試圖從使用$ http切換到Restangular。我的GET似乎很好,但我的POST不是。

的代碼看起來是這樣的:

$scope.addLift = function() { 
    $http.post(url, $scope.Lift); 
    //Restangular.all('lifts').post('Lift', $scope.Lift).then(function (newLift) { 
    // $scope.getLifts(); 
    //}, function (error) { 
    // console.log(error); 
    //}); 
}; 

註釋掉Restangular代碼不起作用,但是$ http.post做,我不知道我做錯了。

如果有幫助,使用Restangular時的POST是http://localhost/api/lifts?LiftName=test,在$http POST請求中,它不包含URL行上的參數,看起來數據在請求正文中。

回答

1

另一個網站上的某個人非常友好,可以幫助我完成此操作。我想我會發布答案,希望它可能會使其他人受益。

Restangular.all('lifts').post($scope.Lift).then(function (newLift) { 
     $scope.getLifts(); 
    }, function (error) { 
     console.log(error); 
    }); 

附加'lift'爭論是沒有必要的post通話。