Link checkbox or popup menu with array in AngularJS?

I'm new to AngularJS, and so I'm confused about how to anchor checkboxes or set popups 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.net/gBcN2/

+4
source share
1 answer

If I understood correctly what you want:

  • You do not have a ng-app definition.
  • In jsFiddle for AngularJS fragments, load the No wrap - in <head> boot mode if you use AngularJS as an external resource.
  • The selected model has its own range because you are using ng-repeat . To understand what I mean, here is a fixed version of your code: http://jsfiddle.net/gBcN2/2/

The first {{selected}} works fine, but the second is "outside" the ng-repeat .

PS:
You do not need to use ng-repeat if you want to use it, as you wrote in your example: a quick script of how I will do it.

Edit:
For flags, this is something like this - http://jsfiddle.net/qQg8u/2/

+2
source

Source: https://habr.com/ru/post/1481715/


All Articles