sacan sacan - 8 months ago 40
AngularJS Question

Get checkboxes to send value instead of boolean

I have checkboxes with values in HTML. The problem is that I want the values to store in the database and not a boolean. How do I do this?


<div class="form-group" >
<label >Bachelor</label><br>

<input type="checkbox" id="ComputerScienceB" ng-model="" value="Computer Science"> Computer Science
<input type="checkbox" id="SystemsEngineeringB" ng-model="" value="Systems Engineering"> Systems Engineering
<input type="checkbox" id="EnvironmentalEngineeringB" ng-model="vm.course.bachelor.environmental" value="Environmental Engineering"> Environmental Engineering
<input type="checkbox" id="MechanicalEngineeringB" ng-model="vm.course.bachelor.mechanical" value="Mechanical Engineering"> Mechanical Engineering
<input type="checkbox" id="BiotechnologyB" ng-model="" value="Biotechnology"> Biotechnology

<div class="form-group">
<button type="submit" class="btn btn-primary" ng-click="vm.saveCourse()">Add Course</button>

The database inserts the hole vm.course. I am using the hole mean stack.


You need ng-true-value attribute. You can use it like this:

<input ng-true-value="Biotechnology"

See angular docs on input[checkbox]