Access the whole item in ng-options in AngularJS

31 views Asked by At

Not sure how else to title this. I'm using ng-options to generate a drop down. The source array is of the following form:

[{
    id:1,
    name: 'Bob'
 },
 {
    id:2,
    name: 'Tom'
 }...(etc)
]

my ng-options looks like this:

ng-options="item.name as item.name for item in myObj

which I need since the ng-model is to the name elsewhere. However, on the ng-change, I want to send (among other things) the item.id. But I can't figure out how to access that at that point. Not only is item.id undefined in the ng-change, even item is undefined at that point. But, I can't use it in the `ng-options since I need it to model to the name elsewhere.

How do I access item.id for use in the ng-change?

1

There are 1 answers

1
Dariusz On

This should do the trick:

item as item.name