I'm having the same problem. For me, it's deleting multiple items after
calling a $resource API.
var promiseArray = _.map(deleteList, function(item) {
return api[$scope.resourceType].delete({id: item.id}, function() {
// Remove from the view
//list.splice(item.index, 1);
}).$promise;
});
$q.all(promiseArray).then(function() {
_.each(deleteList, function(item) {
list.splice(item.index, 1);
});
});
The ideal solution is to delete the items from the list in the first
callback, but that didn't work so I commented it out and tried the promise
then function. There's no difference in results between the two methods:
splicing more than two elements always leaves at least one, usually more,
items in the array.
I'm looking for a solution as well.
On Saturday, August 2, 2014 2:45:13 PM UTC-4, Rishabh Shukla wrote:
>
> Hi all,
>
> I am trying to make a call to a function, which looks something like this:
>
> scope.deleteCharge = function (outerIndex, innerIndex) {
>
> if (outerIndex >= 0 && innerIndex >= 0) {
> scope.charges.clients[outerIndex].splice(innerIndex, 1);
> } else {
> //some stuff here
> }
> }
>
> }
>
> So, here scope.charges is kind of a two dimensional array and I am passing
> an innerIndex and outerIndex as arguments in the function.
>
> The HTML view looks something like this:
>
> <li ng-repeat="client in addedClients" ng-init="outerIndex = $index">
> <tr ng-repeat="charge in charges.clients[outerIndex]"
> ng-init="innerIndex = $index">
> <td>Some Stuff</td>
> <td><a ng-click="deleteCharge(outerIndex, innerIndex)"></a></td>
> </tr>
> </li>
>
> This is the simplified code but you can assume all other scope variables
> like "addedClients" are already there.
>
> So, basically I am having nested ng-repeats here and after clicking on
> the this "deleteCharge" button I am calling the
> "scope.deleteCharge(outerIndex, innerIndex)" function as shown above.
>
> Now, when I click on the button to call the function it doesn't properly
> change the UI and results in unstable state.
>
> I have tried to call scope.$apply(), but it throws an error: "Error:
> [$rootScope:inprog] $apply already in progress". Probably because this is
> already within an executing function.
>
> Any idea about how I can make that work?
>
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.