0

I have the following types:

$scope.types = [{
  name: 'First',
  desc: 'first desc'
},{
  name: 'Second',
  desc: 'second desc'
}]

I create a select:

  <div>
    <select ng-model="object.type" ng-selected="type.name" ng-options="type.name for type in types"></select>
  </div>

And my model looks like this:

$scope.object = {type: 'First'};

When I set that model the select box is not selected to the correct element. Pretty sure I know exactly why this is happening. My type list is a list of objects and my model.type is just a string not an object. I really do want my types to have the extra 'desc' information and cannot change the model. Is there a way to set-up my select such that it works?

4

2 回答 2

1

将理解表达式更改为

ng-options="type.name as type.name for type in types"
于 2013-08-06T22:15:57.673 回答
0

或者....

只需在这样的范围内分配它:

$scope.object = {type: $scope.types[0]}
于 2013-08-06T23:41:57.043 回答