Sam Bush Sam Bush - 3 months ago 11
AngularJS Question

AngularJS If Checkbox is check display

Can someone show me the correct syntax for creating a If/Else statement for the ng-repeat?
In short, If box is checked display max number range. If unchecked display min.
I have searched and searched, but I can't find the syntax for doing it on the page and not inside the controller.

**json**
{
"min": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
"max": ["91", "92", "93", "94", "95", "96", "97", "98", "99", "100"]
}

**Inside my controller declaring scope**
$scope.min = response.data.min;
$scope.max = response.data.max;

**display.html**
<input type="checkbox" name="min-max" id="min-max" class="css-min-max" checked="checked"/>

<div ng-repeat="info in min"> <--- this is my problem.
<p>{{info}}<p>
</div>

Answer

Perhaps you're looking for something more than the use-case you described(there are fine solutions in other answers)

Here is a long way:

<body ng-app="listByCheckbox" >
  <div ng-controller="listDisplayCtrl">
     <input type="checkbox" ng-model="checkedList"   ng-init="checkedList=true"/> 
       Check the box for low numbers, un-check box for high numbers
       <div ng-value= "selectedList = checkedList ? listOptions.min : listOptions.max"  >
          <p ng-repeat="info in selectedList">{{info}} is a fine number.<p>     
       </div>
   </div>
</body>

with a controller with no logic in it as you requested like this:

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

  app.controller('listDisplayCtrl', function ($scope) {

    $scope.listOptions = {
      "min": ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"],
      "max": ["91", "92", "93", "94", "95", "96", "97", "98", "99", "100"]
    }

  })

fiddle