0

I'm trying to make a check box that should be ticked when a value from the controller is filled (!= null). It also need to be able to be ticked off and on, but I can't get it to work:

<input type='checkbox'
   ng-false-value="''"
   ng-model="entry[element.propertyName]"
   id="q{{element.id}}"
   ng-checked="entry[element.propertyName] != ''"
    >

The check box is ticked when entry[element.propertyName] is filled, so far so good. But when I untick the check box the model remains unchanged, even though I've set ng-false-value, and the 'selected=selected' attribute doesn't disappear. When I tick and untick again, then the model starts to change to true and ''

Should be the easiest thing in the world, what am I missing here?

I'm using Angular 1.3.11

2 Answers2

1

I have no idea why you are using ng-false-value, never saw that before. Here is a snippet with a button updating a checkbox.

function testCtrl($scope){
 // Initialise the checkbox as unckecked
 $scope.testIsChecked=false;

 // This function makes the checkob checked
  $scope.makeItCHecked = function(){
  $scope.testIsChecked=true;
  }
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app>
<div ng-controller="testCtrl">
  <div><input type="checkbox" ng-model="testIsChecked">
   $scope.testIsChecked value : {{testIsChecked}}</div>
<button ng-click="testIsChecked=true">Make it checked</button>
   
</div>
</div>
Renan Le Caro
  • 365
  • 1
  • 7
-1

See this link for explanation. You can include the array in an object like: public class objElement { string[] propertyName; } and then bind to your checkbox.

Community
  • 1
  • 1
Shalabh Raizada
  • 354
  • 2
  • 8