Angularjs angular$resource在对象更改时删除属性
我创建了一个返回$resource的服务Angularjs angular$resource在对象更改时删除属性,angularjs,Angularjs,我创建了一个返回$resource的服务 module.registerFactory('Website', function ($resource, $cacheFactory) { var cache = $cacheFactory('websites'); var pagedCache = $cacheFactory('websites_paged'); return $resource('/api/websites/:id', {id: '
module.registerFactory('Website', function ($resource, $cacheFactory) {
var cache = $cacheFactory('websites');
var pagedCache = $cacheFactory('websites_paged');
return $resource('/api/websites/:id', {id: '@id'}, {
query: {method: 'GET', isArray: false, cache: pagedCache},
get: {method: 'GET', cache: cache}
});
});
在编辑状态下,我通过调用
$scope.website = Website.get({'id': $stateParams.id});
$scope.website承诺按预期包含我的数据。(下面是来自服务器的缩短JSON结果)
我的问题是目标属性。
在我的EditCtrl中,我打开一个模式并将目标作为所选项目发送到模式。那很好用
$scope.selectObjectives = function () {
var modalInstance = $modal.open({
templateUrl: 'app/modules/objectives/templates/select-objectives.html',
controller: 'SelectObjectivesModalCtrl',
size: 'lg',
resolve: {
selectedItems: function () {
return $scope.website.objectives;
}
}
});
modalInstance.result.then(function (selectedItems) {
$scope.website.objectives = selectedItems;
console.log($scope.website);
});
}
关闭模式时,新选择的编辑项将被注入回$scope.website.objectives。(cfr.modalInstance.result.then()…)
控制台完美地记录了所有属性,包括目标
现在是奇怪的部分:
一旦我尝试在另一个功能中访问$scope.website(ie更新)
目标属性已从$scope.website中删除
这是我的更新方法:
$scope.updateWebsite = function () {
console.log($scope.website);
$scope.website.$save(function () {
$cacheFactory.get('websites').remove('/api/websites/' + $scope.website.id);
$cacheFactory.get('websites_paged').removeAll();
$state.go('app.websites');
});
};
控制台将所有属性记录在$scope.website中-目标除外。这是完全删除
我希望我说得够清楚了。
谢谢你花时间帮我指出正确的方向。我的错。
我的回复没有像RESTful帖子中应该返回的那样返回整个对象
$scope.updateWebsite = function () {
console.log($scope.website);
$scope.website.$save(function () {
$cacheFactory.get('websites').remove('/api/websites/' + $scope.website.id);
$cacheFactory.get('websites_paged').removeAll();
$state.go('app.websites');
});
};