Angular:正确使用ng-options

时间:2015-04-29 17:31:48

标签: angularjs

使用ng-options遍历{title: '', value: ''}的对象以显示title中的select list并使用控制器中的value,但我得到了完整的对象而不是vlaue。 这是视图代码:

  <select class="form-control" ng-model="item.action" ng-options="option.title for option in options">
              </select>

控制器代码:

  $scope.options = [{
    title: 'title one',
    value: 'value one'
  }, {
    title: 'title two',
    value: 'value two'
  }];

$scope.item = {};
$scope.item.action= $scope.actio.value; // here am getting the obect title and value when i want to pull only the value

1 个答案:

答案 0 :(得分:0)

根据https://docs.angularjs.org/api/ng/directive/ngOptions#-select-as-and-track-by-,您可以尝试:

<select class="form-control" ng-model="item.action" ng-options="option.value as option.title for option in options">
</select>