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>
</select>


w
has following properties:


  • wrk_worker_id

  • wrk_forename

  • wrk_surname



and so on!

is it possible to bind
search.wrk_worker_id
to
w.wrk_worker_id
, but still show
w.wrk_forename
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}}
   </option>
</select>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download