How can I update an item from a ng-repeat in a function? I have the following code. The repeat in my HTML file:
<div ng-repeat='item in collection'>
<div class="product-item">
<img src="{{item.image}}"/>
{{item.name}}
{{item.price}}
<a ng-href='' ng-click='showPricePopup(item)'>Update price</a>
</div>
</div>
I'm using Angular modal service (http://dwmkerr.github.io/angular-modal-service/) and created the following function in the Controller:
$scope.showPricePopup = function(item){
ModalService.showModal({
templateUrl: "/winkelier/modal/price",
controller: "priceCtrl",
inputs: {
item: item
}
}).then(function(modal) {
modal.close.then(function(result) {
console.log("result", result.item);
$scope.updateItem(result.item);
item = result.item;
})
})
}
In priceCtrl I inject $scope, item and close and copy item to the scope.
angular.module('myApp').controller('priceCtrl', ["$scope", "$http", 'item', 'close', function($scope, $http, item, close) {
$scope.modalitem = angular.copy(item);
$scope.savedmodalItem = angular.copy($scope.modalitem);
I created a close() and cancel() function also in this controller:
$scope.close = function(){
close({
item: $scope.modalitem
}, 500);
}
$scope.cancel = function(){
$scope.modalitem = angular.copy($scope.savedmodalItem);
close({
item: $scope.modalitem
}, 500);
}
The problem is as follows: When I update some property's from item and click the cancel() button, nothing happens. That's fine. But, when I change some property's and I click close(), the item will be updated via $scope.updateItem(), but the item in the ng-repeat will not be updated.
How can I solve this?