【发布时间】:2014-01-17 16:48:06
【问题描述】:
我正在尝试使用 RESTAngular 发出 PUT 请求。我对 Angular 和 RESTAngular 都很陌生。
下面是代码 sn-p,它可以工作。
$scope.itemToUpdate = Restangular.all($scope.slug);
$scope.itemToUpdate.getList().then(function(items){
var item = items.one($routeParams.id);
item.name = $scope.singular.name;
item.description = $scope.singular.description;
item.put();
});
这不起作用。
$scope.itemToUpdate = Restangular.all($scope.slug);
$scope.itemToUpdate.getList().then(function(items){
var item = items.one($routeParams.id);
item = $scope.singular;
item.put();
});
不知道我做错了什么。
$scope.singular 最初获取它的数据如下。 Restangular.one('roles', $routeParams.id).getList().$object.
基本想法是从表单更新此模型,并在 slug 与 id 匹配时使用相关数据预填充表单。如果需要,我可以更改连接方式。因此,请随时提出最佳做法。
编辑 2
这个官方demo对解决问题很有帮助。 http://plnkr.co/edit/d6yDka?p=preview
【问题讨论】:
标签: angularjs restangular