Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS select ng-model

Tags:

angularjs

I use the following select statement:

<select ng-model="vm.institution" ng-options="c as c.institutionName for c in vm.institutionsOfUser"></select>

In my model, the institution is stored but what I will have is to onyl store the id of the institution selected (and contained in vm.institutionsOfUser-> id)

Is there a possibility to do this?

like image 717
quma Avatar asked Jan 28 '26 17:01

quma


1 Answers

You just need to change ngOptions a little c.id as c.institutionName for c in vm.institutionsOfUser:

<select ng-model="vm.institution" 
        ng-options="c.id as c.institutionName for c in vm.institutionsOfUser"></select>

This will bind model to institution id instead of entire object.

like image 132
dfsq Avatar answered Jan 31 '26 16:01

dfsq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!