AngularJS和列表框(选择多个)

时间:2017-09-09 11:13:52

标签: angularjs

我有以下内容:

<div>
<select multiple>
    <option ng-model="xss" ng-selected="u.selected" ng-repeat="u in xs" value="{{u.value}}">
        {{u.value}}
    </option>
</select>

$scope.xss;
$scope.xs = [
    { id: 1, value: 'value 1', selected: false },
    { id: 2, value: 'value 2', selected: false },
    { id: 3, value: 'value 3', selected: false }
];

选择工作正常,但所选值未绑定到xss。如何从多个选择角度中选择项目?

1 个答案:

答案 0 :(得分:5)

您应该在<select>语句中使用ng-model而不是以下选项,

<select multiple ng-model="xss" >
    <option ng-selected="u.selected" ng-repeat="u in xs" value="{{u.value}}">
      {{u.value}}
    </option>
  </select>

<强> LIVE DEMO