2014-11-04 57 views
0

我想在角控制器創建一個更新功能PUT請求:

$scope.update = function(product){ 
    product.$save(); 
    $scope.cancelEdit(); 
} 

我的後端有更新資源兩條路線:

PATCH /products/:id(.:format) 
PUT /products/:id(.:format) 

但是,我無法使用$resource來訪問這些中的任何一個!所以,我怎麼打算髮送補丁或PUT請求

{ 'get': {method:'GET'}, 
    'save': {method:'POST'}, 
    'query': {method:'GET', isArray:true}, 
    'remove': {method:'DELETE'}, 
    'delete': {method:'DELETE'} }; 

According to the docs,我既可以使用這些功能與某些HTTP動詞發送請求?

我應該如何在中心配置此應用程序?

回答

2

這些只是默認值,但per the documentation for $resource您可以定義自己的操作。

$resource(url, paramDefaults, { 
    put: {method: 'PUT'}, 
    patch: {method: 'PATCH'}, 
}); 
+0

只有在幾天前開始學習角度...你應該把這個配置作爲一個重要的改變?我可以放入'config'功能嗎?即'angular.module('myApp',['ngResource']).config(函數($ resource {...'? – Starkers 2014-11-04 21:17:14