Using $index from ion-slide to search object

Hi!
I’m using a <ion-slide-box> with the on-slide-changed option.
I’m using it like this:

<ion-slide-box on-slide-changed="lektionSlideHasChanged(index)" ng-repeat="stuff in stuffs">
    <ion-slide ng-repeat="thing in stuff">
    ..stuff foreach thing
    </ion-slide>
</ion-slide-box>

With my $index I want to use it as a key in an object to get some data (that is also displayed in the <ion-slide>) and highlight it in a header.

first i tested just accessing the index by adding it to a variable on the scope.

$scope.lektionSlideHasChanged = function($index) {
    $scope.highlight = $index;
}

Works perfect. But when I try to use the $index as key in my json object like this:

$scope.lektionSlideHasChanged = function($index) {
    $scope.highlight = $scope.stuffs[0][$index]['key'];
}

It starts behaving really odd. On some slides it works, but on others it gives me the following error message:

TypeError: 'undefined' is not an object (evaluating '$scope.stuffs[0][$index]['key']')

Is this a bug or is this something you just cannot do? Is there a workaround?

Never mind, there were irregular keys in my array of data. Which med the $index point to an unidentified object. Just as the error said…

Glad to see you got this resolved :smile: