2016-06-01 82 views
0

我有複選框,其值爲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。我正在使用孔平均值堆棧。

+0

您可以用'NG-真值= 「一些」' –

回答

2

您需要ng-true-value屬性。您可以使用它像這樣:

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

angular docs on input[checkbox]

+0

謝謝,成功了! – sacan