I'm using this collection for showing all the items using ng-repeat in an index view.
In this view I have a button that opens a modal for editing the chosen item.
This modal is created with a service provided by ui.bootstrap, and has
its own controller, which first resolve the chosen item and then add it to
its $scope.
resolve: {
negocio: function() {
return utils.encontrarPorId($scope.negocios, negocioId)
},
}
// in the modal controller
$scope.negocio = negocio
The function called encontrarPorId receives as arguments an array (the collection)
and an Id (the one of the chose item) and returns the item of the collection that matches the Id.
In the view associated to the modal controller, I use $scope.negocio in a form for getting
the user input, and this form has a submit button that saves the changes:
$scope.negocio.$save()
The problem is that when the users edit the item info using the form, $scope.negocio changes
immediately because of the angular data binding, and it doesn't matter if the modal is cancelled (closed)
whithout pressing the submit button or if the user click the submit button and the PUT request fail,
the item info in the collection gets modified.
Right now I'm resolving the item in the controller making a new request to the API for avoiding this issue
But I'll like to resolve the item from the collection without making a new request to the API, because I
already have the item info, don't want to bring it again.
Looking for a solution to my problem found the restmod issue #49 and thought it could be related.
this is the description of the reason for opening this issue
First, I create a restmod model:
Then, I'm resolving a collection for my controller using the model called 'Negocio':
and then adding it to the
$scope
I'm using this collection for showing all the items using
ng-repeat
in an index view. In this view I have a button that opens a modal for editing the chosen item. This modal is created with a service provided byui.bootstrap
, and has its own controller, which first resolve the chosen item and then add it to its$scope
.The function called
encontrarPorId
receives as arguments an array (the collection) and an Id (the one of the chose item) and returns the item of the collection that matches the Id.In the view associated to the modal controller, I use
$scope.negocio
in a form for getting the user input, and this form has a submit button that saves the changes:The problem is that when the users edit the item info using the form,
$scope.negocio
changes immediately because of the angular data binding, and it doesn't matter if the modal is cancelled (closed) whithout pressing the submit button or if the user click the submit button and the PUT request fail, the item info in the collection gets modified.Right now I'm resolving the item in the controller making a new request to the API for avoiding this issue
But I'll like to resolve the item from the collection without making a new request to the API, because I already have the item info, don't want to bring it again.
Looking for a solution to my problem found the restmod issue #49 and thought it could be related.
Thanks for your help :)