获取复选框以发送值而不是布尔值

时间:2016-06-01 08:01:25

标签: html angularjs checkbox mean-stack

我有HTML格式的复选框。问题是我希望值存储在数据库中而不是布尔值。我该怎么做?

HTML:

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

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


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

数据库插入孔vm.course。我正在使用洞平均堆栈。

1 个答案:

答案 0 :(得分:2)

您需要ng-true-value属性。您可以像这样使用它:

<input ng-true-value="Biotechnology"
  type="checkbox"
  id="BiotechnologyB"
  ng-model="vm.course.bachelor.bio">

请参阅angular docs on input[checkbox]