I decided to take my project in the Restangular, but I have some problems in the SAVE and UPDATE operations.
I use the API restheart with mongodb.
In SAVE in my case, I'm saving a New Post, and when by chance I make any changes, it saves a new post out instead of updating it.
UPDATE on, I can update the first instance, for example, make a change in title and saved, it updated if I update again .. generates this error:
PUT http://127.0.0.1:8080/api/portfolio/55ef4b15ef862e8f7316cbf1 412 (Precondition Failed) Follow my resource and code:
Restangular.all($scope.section).getList($scope.query).then(function(res){
$scope.items = res;
});
my SAVE:
// create new object item
$scope.item = Restangular.one($scope.section);
// save object
$scope.addItem = function(){
$scope.item.save().then(function(){
toast.msgToast($scope.section + ' ...item criado!');
}, function(err){
toast.msgToast($scope.section + ' ...ocorreu um erro ao criar o item!');
});
};
my UPDATE:
$scope.updateItem = function(){
$scope.item.save().then(function(){
toast.msgToast($scope.section+ ' #' +$scope.item._id.$oid+ ' ....Atualizado!');
});
};
$scope.loadItem = function(){
Restangular.one($scope.section, $stateParams.id).get().then(function(item) {
$scope.item = item;
});
};