1

AngularJSのドキュメント では、新しいオブジェクトではなく、既存のオブジェクトのみを保存できるようです。つまり、パラメータがゼロの$saveon メソッドがあります。$resource

を使用してサーバーに新しいPOSTオブジェクトを送信するにはどうすればよいですか?$resource

ドキュメントが著しく不足しています。

4

1 に答える 1

3

Resource.saveオブジェクトをパラメーターとして受け取ります。

http://docs.angularjs.org/api/ngResource.$resource

var Item = $resource("/api/items/:id", {id: "@id"});
//Item is the "model", you have the method unprefixed
$scope.items = [];
$scope.addItem = function () {
  var item = Item.save({name: $scope.newItemName}); //unprefix call
  $scope.items.push(item);
  $scope.newItemName = '';
};
$scope.saveItem = function (item) {
  // item is, this time, a "Item instance" (returned by Item.save)
  // and has the functions prefixed
  item.$save();
}

POST私たちのチャットから、オブジェクトにはこれで十分 (最低限)のようです。

$resource('/some/path').save({name: 'Fred'});
于 2013-05-25T16:37:02.067 に答える