ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

bug: ion-reorder causes ng-repeat item to dissapear or be empty

Open paynoattn opened this issue 11 years ago • 1 comments

Type: bug

Platform: desktop browser

Hello,

I'm trying to use ion-reorder in my app. The re-order icons appear, and I can drag items, but when I drop them either the item or the content inside the list item completely dissapears. I basically copy and pasted the ion-reorder from the documentation as you can see below, only changing the name from my data.

This is on ionic serve on latest Chrome/Firefox/Safari.

index.html

<ion-list show-reorder="data.showReorder">
          <ion-item  ng-repeat="artist in artists | filter: query" class="item-thumbnail-left item-text-wrap">
            <img src="img/{{artist.shortname}}_tn.jpg">
            <h2>{{artist.name}}</h2>
            <ion-reorder-button class="ion-navicon" on-reorder="moveItem(item, $fromIndex, $toIndex)"></ion-reorder-button>
          </ion-item>
        </ion-list>

app.js

$http.get('../model/data.json').success(function(data) {
    $scope.artists = data.artists;
    $scope.moveItem = function(item, fromIndex, toIndex) {
      //Move the item in the array
      $scope.artists.splice(fromIndex, 1);
      $scope.artists.splice(toIndex, 0, item);
    };

Also when I try to console.log(item); at the end of my $scope.moveItem function it states that item is undefined in the console.

paynoattn avatar Oct 16 '15 21:10 paynoattn

Okay, I figured this out. The fix is that I was passing the item instead of artist. Artist is the variable of the repeat item, so therefore item would be undefined.

In my case I had to change these to fix this: index.html

<ion-list show-reorder="data.showReorder">
          <ion-item  ng-repeat="artist in artists | filter: query" class="item-thumbnail-left item-text-wrap">
            <img src="img/{{artist.shortname}}_tn.jpg">
            <h2>{{artist.name}}</h2>
            <ion-reorder-button class="ion-navicon" on-reorder="moveItem(artist, $fromIndex, $toIndex)"></ion-reorder-button>
          </ion-item>
        </ion-list>

app.js

$http.get('../model/data.json').success(function(data) {
    $scope.artists = data.artists;
    $scope.moveItem = function(artist, fromIndex, toIndex) {
      //Move the item in the array
      $scope.artists.splice(fromIndex, 1);
      $scope.artists.splice(toIndex, 0, artist);
    };

paynoattn avatar Oct 19 '15 18:10 paynoattn