我是AngularJS的新手,因此对于如何将复选框或多选下拉列表绑定到单独的列表感到困惑。
<body ng-controller="FooListCtrl">
<span ng-repeat="foolist in foos">
<select ng-model="selected" ng-options="foo for foo in foolist" multiple="">
</select>
</span>
</body>
'use strict';
function FooListCtrl($scope) {
$scope.foos = {"Bar": [ "foo", "bar"]};
$scope.selected = [];
}
FooListCtrl.$inject = ['$scope'];
答案 0 :(得分:2)
如果我做对了你想要的东西:
ng-app
定义。 No wrap - in <head>
加载模式。selected
拥有自己的“范围”,因为您使用ng-repeat
。要了解我的意思,这里是您的代码的固定版本:
http://jsfiddle.net/gBcN2/2/ 首先{{selected}}
工作正常,但第二个是ng-repeat
范围的“外部”。
PS:
如果您想像在示例中所写的那样使用ng-repeat
,则不必使用{{1}}:quick fiddle of how I'd do it.
修改强>
对于复选框,它就是这样的 - http://jsfiddle.net/qQg8u/2/