Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I have array of objects in Angular JS.

For showing this array I use ng-repeat with filter by value from input field.

Problem is that when I typing text in field ng-repeat makes filtering and changes indexes of array.

Default array before filtering:

0 => obj(o)
1 => obj(b)
2 => obj(c)

If I type "b" I get output list:

0 => obj(b)

But with index 0, if element is one. So index 0 had obj(o) before filtering.

How I can save indexes that will be 1 => obj(b) after filtering?

share|improve this question
up vote 1 down vote accepted
 $scope.defaultArray = [
        0 => obj(o)
        1 => obj(b)
        2 => obj(c)
     ];
     $scope.filteredArray = $scope.defaultArray;

Use filteredArray variable in your ng-repeat Then for every element remaining in filteredArray you can get its index by doing this : $scope.defaultArray.indexOf(obj(b)) if I search "b"

share|improve this answer
    
What do you mean? Read please question again – Babaev Aug 18 at 21:32
    
Looks like a good answer to me. Maybe you need to provide your code. – Mike Aug 18 at 21:35
    
i edited my answer – debugall Aug 18 at 21:43
    
Can you edit answer please – Babaev Aug 19 at 10:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.