user1260928 user1260928 - 8 months ago 36
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...


Try This

vm.moisChanged = function(mois){
    var i =, index) {
        if(obj.libelle == mois.libelle) {
            return index;