samedi 30 juillet 2016

AngularJS multiple checkboxes doubts (Angular Material)

I'm trying to get multiple Angular Material checkboxes with the same ng-model. I have two problems: how to get default checked checkboxes, and how to make at least one of these checkboxes to be required. I tried with ng-checked, but then I can't POST the values through the form.

HTML

      <label for="inputPassword3" class="col-sm-2 control-label">Školski sat *</label>
      <div class="col-sm-10" >
        <span class="col-sm-2" ng-repeat="period in periods">
          <md-checkbox ng-model="form.periods[period]" ng-click="toggle(period, selected)">
            . sat
          </md-checkbox>
        </span>
      </div>

App.js

$scope.periods = [1,2,3,4,5,6,7,8,9,0]; /*broj sati*/
      $scope.selected = [2];
      $scope.toggle = function (period, list) {
        var idx = list.indexOf(period);
        if (idx > -1) {
          list.splice(idx, 1);
        }
        else {
          list.push(period);
        }
      };
      $scope.exists = function (period, list) {
        return list.indexOf(period) > -1;
      };

Please, help.




Aucun commentaire:

Enregistrer un commentaire