search

Home  >  Q&A  >  body text

angular.js - Questions about angular's select

js part:

$scope.sex = [{'name':'男', 'value':'man'},{'name':'女', 'value':'women'}];

html part:

<select ng-model="sexOptions" ng-options="x.value as x.name for x in sex">
    <option value="">请选择</option>
</select>

The problem I am encountering now is:
I obtained the data results from the server. If the user's profile is "male", then this select must select the male item

This is how I bound it

$scope.sexOptions = {'value':res.farmersInfo.sex};

As shown below:

Binding can now be achieved, but when I select the option again, for example, I select the gender as female:
As shown below:

The problem arises, I selected female, but the default "Please select" is displayed

How to solve this problem?
Thank you everyone! ! ! !
Very anxious!

高洛峰高洛峰2872 days ago600

reply all(1)I'll reply

  • 滿天的星座

    滿天的星座2017-05-15 17:12:37

    <select ng-model="sexOptions.value"> try this?

    reply
    0
  • Cancelreply