在我的factory
return $resource('rest/records/:id', {}, {
query: {
method: 'GET',
isArray: true,
// RestSQL has an extra struct around the array
transformResponse: function(data) {
return angular.fromJson(data).records;
}
},
create: { method: 'POST' },
update: { method: 'PUT', params: {id: '@id'},
});
service
使用的是controller
使用的。
我在控制器中获得了正确的记录。
然后当我编辑并想要保存记录时
我做record.$update()
;
我的休息POST成功,因为我从服务器获得了有效的响应。
但是来自服务器的响应只是某种成功消息,例如"{ "number": 2 }"
。
现在我有一个使用此记录属性的角度模板,例如{{record.image}}
但是我一记录。$ update();
记录属性disapper和记录现在看起来像
record = {“number”:2}
所以我应该将整个记录作为对POST操作的响应返回,还是应该以其他方式更新,以便记录不会被服务器的响应覆盖?
当然,暂时解决这个问题的方法是
$scope.temp = jQuery.extend(true, {}, $scope.record);
$scope.temp.$update();
答案 0 :(得分:0)
我将在POST
,PUT
等上返回更新后的对象(另请参见:Should a RESTful 'PUT' operation return something)。所以,