How do I set the value property in AngularJS' ng-options?

后端 未结 27 828
感动是毒
感动是毒 2020-11-22 08:17

Here is what seems to be bothering a lot of people (including me).

When using the ng-options directive in AngularJS to fill in the options for a &

相关标签:
27条回答
  • 2020-11-22 09:09

    For an object:

    <select ng-model="mySelect" ng-options="key as value for (key, value) in object"></select>
    
    0 讨论(0)
  • 2020-11-22 09:09

    The tutorial ANGULAR.JS: NG-SELECT AND NG-OPTIONS helped me solve the problem:

    <select id="countryId"
      class="form-control"
      data-ng-model="entity.countryId"
      ng-options="value.dataValue as value.dataText group by value.group for value in countries"></select>
    
    0 讨论(0)
  • 2020-11-22 09:10

    The ng-options directive does not set the value attribute on the <options> elements for arrays:

    Using limit.value as limit.text for limit in limits means:

    set the <option>'s label as limit.text
    save the limit.value value into the select's ng-model

    See Stack Overflow question AngularJS ng-options not rendering values.

    0 讨论(0)
提交回复
热议问题