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:

  1. you don't have ng-app definition.
  2. on jsfiddle snippets of angularjs put no wrap - in <head> load mode, if using angularjs external resource.
  3. model selected has it's own "range", because use ng-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

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -