0

I have a unique problem with ng-select. I have multiple select boxes populated with the same $scope.list (this is an important requirement).

The items can be selected only once in series of dropdowns. I am not able to implement this - since deleting the $scope.list removes the item from the previous select box.

<div ng-repeat="element in anotherList">
    <select ng-options="o for o in list" ng-model="abc" required>
 </div>
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Struggler
  • 672
  • 2
  • 9
  • 22
  • 1
    see about `disabled` in [ngOptions doc](https://docs.angularjs.org/api/ng/directive/ngOptions) – Grundy Aug 30 '15 at 12:12

1 Answers1

0

I ended up using ng-repeat with ng-disabled

App.js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.b  = [1, 2, 3];
  $scope.list = ["Quora", "SOf", "Wikipedia", "Google", " Wolfram Alpha"];

  $scope.isDisabled = {
    "Quora": false,
    "SOf": false,
    "Wikipedia": true,
    "Google": false,
    "Wolfram Alpha": false
  };
  $scope.updateDisabled = function(model){
    $scope.isDisabled[model] = !$scope.isDisabled[model];
  }
});

Index.html

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.3.x" src="https://code.angularjs.org/1.3.17/angular.js" data-semver="1.3.17"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <div class="container" ng-repeat="a in b">
      <select class="select" 
      ng-model="abcd"
      ng-change="updateDisabled(abcd)"
      >
        <option value="">Choose unique</option>
        <option 
          ng-repeat="o in list"
          ng-disabled="isDisabled[o]"
        >{{o}}</option>

      </select>
    </div>
  </body>

</html>

Here is the plunkr

Struggler
  • 672
  • 2
  • 9
  • 22
  • this appears to be a link only answer, and attempting to use formatting codes to avoid the requirement of posting code with plunkr links is not appropriate. in fact, the link isn't rendering correctly at all. – Claies Aug 31 '15 at 02:53