javascript - Bind checkbox or multi-select dropdown to array in AngularJS? -
i new angularjs, , confused how bind checkboxes or multi-select dropdowns separate list.
<body ng-controller="foolistctrl"> <span ng-repeat="foolist in foos"> <select ng-model="selected" ng-options="foo foo in foolist" multiple=""> </select> </span> </body> 'use strict'; function foolistctrl($scope) { $scope.foos = {"bar": [ "foo", "bar"]}; $scope.selected = []; } foolistctrl.$inject = ['$scope']; run code: http://jsfiddle.net/gbcn2/
if got right want:
- you don't have
ng-appdefinition. - on jsfiddle snippets of angularjs put
no wrap - in <head>load mode, if using angularjs external resource. - model
selectedhas it's own "range", because useng-repeat. see mean, here fixed version of code: http://jsfiddle.net/gbcn2/2/
first {{selected}} works fine, second "outside" of ng-repeat scope.
ps:
don't have use ng-repeat if want use wrote in example: quick fiddle of how i'd it.
edit:
checkboxes it's - http://jsfiddle.net/qqg8u/2/
Comments
Post a Comment