-5

For example lets take an array example

$scope.users = ['John','Peter'];

How to get the index of John ?

2

3 Answers 3

2
$scope.users.indexOf('John')

This is not angular specific. This is a JS array method.

Sign up to request clarification or add additional context in comments.

Comments

0

try this in your view html {{users.indexOf('John')}} or in your controller use $scope.users.indexOf('John')

Comments

-1

Use track by $index.

E.g. <p ng-repeat = "user in $scope.users track by $index"></p>

Then you can determine if it's John:

<p ng-repeat = "user in $scope.users track by $index">
  <span ng-if="$scope.users[$index] === 'John'">Here's John at {{$index}}</span>
</p>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.