Moritz Büttner Moritz Büttner -4 years ago 81
AngularJS Question

set ng-model to property of ng-repeat?

I have select-box in my view where you can select a worker.

<select ng-model="search.wrk_worker_id">
<option ng-repeat="w in workers.message">{{w.wrk_forename}}</option>

has following properties:

  • wrk_worker_id

  • wrk_forename

  • wrk_surname

and so on!

is it possible to bind
, but still show
in the select box ?

Answer Source

you specify a value property on your option this is the value that will bind to search.wrk_worker_id after you select the option in the selectbox:

<select ng-model="search.wrk_worker_id">
   <option ng-repeat="w in workers.message" value={{w.wrk_worker_id}}>{{w.wrk_forename}}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download