Angularjs IF - 对复选框

时间:2015-12-07 09:44:21

标签: angularjs checkbox

我是Angular js的新手我想问我有一个案例,如果复选框被选中或者为真,我必须返回“YES”,并且当值为false或未选中时想要返回“NO”。

实际上我的数据存储在数据库中的“Tinyint”1或0形式我想要做1时发生它显示YES任何解决方案任何帮助将不胜感激。 这是我的HTML

 <form class="form-horizontal">
                           <div class="form-group">
                              <label class="col-lg-2 control-label">Name</label>
                              <div class="col-lg-10">
                                 <input type="text" ng-model="rec.Name" placeholder="Name" class="form-control">
                              </div>
                           </div>
                          
                           <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                 <div class="checkbox c-checkbox">
                                    <label>
                                       <input type="checkbox" value="" ng-model="rec.isSpecial">
                                       <span class="fa fa-check"></span>is Special</label>
                                 </div>
                              </div>
                           </div>

                           <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                 <div class="checkbox c-checkbox">
                                    <label>
                       <input type="checkbox" ng-model="rec.isMultiple">
                                       <span class="fa fa-check"></span>Is Multiple</label>
                                 </div>
                              </div>
                           </div>


                           <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                 <button type="button" ng-click="add(rec)" class="btn btn-sm btn-primary">ADD</button>
                              </div>
                           </div>
                        </form>

我需要定位复选框ismultiple和isspecial。

1 个答案:

答案 0 :(得分:0)

你可以像这样使用ng-false-value的ng-true-value:

&#13;
&#13;
 <form class="form-horizontal">
                           <div class="form-group">
                              <label class="col-lg-2 control-label">Name</label>
                              <div class="col-lg-10">
                                 <input type="text" ng-model="rec.Name" placeholder="Name" class="form-control">
                              </div>
                           </div>
                          
                           <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                 <div class="checkbox c-checkbox">
                                    <label>
                                       <input type="checkbox" ng-model="rec.isSpecial" ng-true-value = "YES" ng-false-value="NO">
                                       <span class="fa fa-check"></span>is Special</label>
                                 </div>
                              </div>
                           </div>

                           <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                 <div class="checkbox c-checkbox">
                                    <label>
                       <input type="checkbox" ng-model="rec.isMultiple" ng-true-value = "YES" ng-false-value="NO">
                                       <span class="fa fa-check"></span>Is Multiple</label>
                                 </div>
                              </div>
                           </div>


                           <div class="form-group">
                              <div class="col-lg-offset-2 col-lg-10">
                                 <button type="button" ng-click="add(rec)" class="btn btn-sm btn-primary">ADD</button>
                              </div>
                           </div>
                        </form>
&#13;
&#13;
&#13;