jeudi 19 février 2015

angular input checkbox remove field

I'm fighting with angular input checkboxes. I have a simple input that looks like this...



<input type="checkbox" ng-model="selectedExercise.isTimed" required/>


However, when I uncheck the box it removes the .isTimed field from my object, when I want to set it equal to false. For example...


checked



{
"name": "Work",
"isTimed": true,
"duration": 3,
}


unchecked



{
"name": "Work",
"duration": 3,
}


I have hacked this to work by adding an ng-change function, but it is super hack in that it just checks to see if angular removed the field, then re-adds it. Is there a proper way to setup my input checkbox so angular won't remove the object field when the box is unchecked?





Aucun commentaire:

Enregistrer un commentaire