[Closed] Problem when removing items from $scope.array


I’m haven a problem removing an item in an array with splice.


The problem is that when I remove an item and click the item to open a new state view detail page for this item, the detail page display +1 item detail. The URL and the array are done, but the item detail is wrong.

Is this an angular ui-router issue or I’m doing something wrong?

Somebody knows how can I fix this issue?



Your problem is here :

  return {
    all: function() {
      return shops;
    get: function(shopId) {
      // Simple index lookup
      return shops[shopId];

You are telling it to return the shop in the nth position of the array rather than searching the shops array for one that matches the desired shopId.


Oh @Calendee, thanks a lot for spent your time debugging my code.
I did the change you mentioned an works fine!

get: function(shopId) {
  for (var i=0; i < shops.length; i++)
    if (shops[i].id == shopId)
      return shops[i];

Thanks and regards