1

I use ng-select to populate my options, but I want to pass the selected index, what should be in the ng-change function?

like if the user selected b I will get 1 which is the second index of the array.

http://jsfiddle.net/kqcrL5j3/

<select 
            ng-options="p as a for a in alpa"
            ng-model="selected" ng-change="detectChange('what to pass index here?')"></select>

1 Answer 1

2

change your code like this,

<select ng-options="a for a in alpa" ng-model="selected" ng-init="selected='a'" ng-change="detectChange(selected)"></select>

You can pass the whole selected object and find the index like this,

  $scope.detectChange = function(selected_index){
       var indexno =  $scope.alpa.indexOf(selected_index );
       console.log(indexno)
    }

DEMO

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.