javascriptangularjsangular-chosen

Angular Chosen - Don't bind ng-model to entire object


Using Angular Chosen

https://github.com/localytics/angular-chosen

and testing out the following example

<select multiple
        chosen
        ng-model="state"
        ng-options="s.name for s in states">
  <option value=""></option>
</select>

However, I'm wondering as to how one would bind just the name value for a state object to ng-model?

The options presented will display just the state names, but when chosen, the entire state object is bound to ng-model rather than just the selected name.

Any thoughts would be much appreictaed as always!


Solution

  • You can try this format

    select as label for value in array
    

    eg. s.name as s.name for s in states