admin管理员组文章数量:1414908
I am new to AngularJS, and am thus confused as how to bind checkboxes or multi-select dropdowns to a separate list.
<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'];
Run the code: /
I am new to AngularJS, and am thus confused as how to bind checkboxes or multi-select dropdowns to a separate list.
<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'];
Run the code: http://jsfiddle/gBcN2/
Share Improve this question asked May 20, 2013 at 8:08 Foo StackFoo Stack 2,3257 gold badges25 silver badges25 bronze badges1 Answer
Reset to default 2If I got right what you want:
- You don't have
ng-app
definition. - On jsFiddle for snippets of AngularJS put
No wrap - in <head>
load mode, if you are using AngularJS as external resource. - Model
selected
has it's own "range", because you useng-repeat
. To see what I mean, here is fixed version of your code: http://jsfiddle/gBcN2/2/
First {{selected}}
works fine, but second is "outside" of ng-repeat
scope.
PS:
You don't have to use ng-repeat
if you want to use it like you wrote in your example: quick fiddle of how I'd do it.
Edit:
For checkboxes it's something like that - http://jsfiddle/qQg8u/2/
本文标签: javascriptBind checkbox or multiselect dropdown to array in AngularJSStack Overflow
版权声明:本文标题:javascript - Bind checkbox or multi-select dropdown to array in AngularJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745174752a2646181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论