user1260928 user1260928 - 1 year ago 87
AngularJS Question

Angularjs : get the index of selected object in select tag

I am trying to get the index of the selected item of my like this :

<select class="form-control" id="field_Mois" name="mois"
ng-options="mois as mois.libelle for mois in vm.allMoisForAnnee track by"
ng-change= "vm.moisChanged(vm.currentMois)">

vm.moisChanged = function(mois){
var i = vm.allMoisForAnnee.indexOf(mois);

But I am always getting -1. I don't understand why.

If someone can help me on this...

Answer Source

Try This

vm.moisChanged = function(mois){
    var i =, index) {
        if(obj.libelle == mois.libelle) {
            return index;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download