Index value of select tag


#1

How do i get index value of selected ng-options and how to get the value in the controller?


#2

You can do :

<select ng-model="yourModel" ng-options="item for item in itemList"> </select>

and then use $scope.yourModel as an object, containing your index if set before


#3

do i need to pass anything in my function?? Because i want to obtain index value in the controller


#4

If you have an ng-option, you must have an array of objects, right ?
then you should have objects like this :

var myObject = {
name : “itemName”,
key : “value”,

“id” : “itemID”
}

In your select, you can add ng-change="myFunction(item)"
then in controller you add

$scope.myFunction = function(item){
console.log("Item ID : " + item.id);
}

Is it clear enough ?


#5

yea thank you so much