Run a function to check the index on each change of the select option…
working snippet below:
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.names = ["Emil", "Tobias", "Linus"];
$scope.detectIndex = () => {
for (var i = 0; i < $scope.names.length; i++) {
if ($scope.names[i] == $scope.selectedName) {
$scope.selectedIndex = i;
return;
}
}
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl" ng-init="selectedIndex = null">
<select ng-model="selectedName" ng-options="x for x in names" ng-change="detectIndex()">
<option value="" disabled="disabled">
Choose...
</option>
</select>
<p>you selected: {{ selectedName }} at index: {{ selectedIndex }}</p>
</div>