Set 'value' of checkbox based on data


#1

HI,
I am making a simple ToDo app, I am getting stuck on one part.

I am using ‘ion-checkbox’ to display all ToDo items:

<ion-checkbox ng-repeat="item in toDoListItems" >{{item.post_title}}</ion-checkbox>

How can I set the value of the generated input?

the code below may help explain how I am trying to set the value:

<ion-checkbox ng-repeat="item in toDoListItems" ng-class="{checked:item.custom_fields.checked === true}">{{item.post_title}}</ion-checkbox>

where ‘item.custom_fields.checked’ is a boolean value supplied from the backend.

Can anyone help i’m a noob


#2

You should use the ng-model attribute to get and set the value. For example:

<ion-radio ng-repeat="phase in phases" ng-value="phase" ng-model="calendar.phase">
          Phase {{phase}}
</ion-radio>
```
`ng-value` specifies what part of the `phase` object to use as the value (for me it's a primitive), and `ng-model` is the model which contains the current value and will be updated with the new value.