angularjs在Bootstrap Modal中提交

时间:2014-03-06 09:07:54

标签: javascript angularjs

我有一个Bootstrap 3 Modal,其中包含可供选择的项目列表,该列表通过Angular填充。当您单击列表中的项目时,我会使用一些JS填充隐藏字段以保存所选值,请参阅下文。隐藏字段与$ scope相关联。当我提交表单时,项目不会通过。我看过一些评论,建议我需要引用父范围,例如: ng-model =“$ parent.Description”,但这似乎也不起作用。有什么建议吗?

$scope.OpenFavsModal = function () {
                  var url = "/GetFavs/";
                  $http.get(url)
                        .success(function (data) {
                            $scope.myData = data;
                            $('#AddFavsModal').modal('show');

                        });
              };


    <form class="form-horizonatal" ng-submit="InsertFavourite()" id="frmAddFav">
    <div class="modal fade" id="AddFavsModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >

                <div class="modal-dialog">
                  <div class="modal-content">
                    <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                      <h4 class="modal-title"><strong>Add</strong></h4>
                    </div>
                       <div class="modal-body">

                            <input type="text" id="hidDescription" class="form-control" ng-model="myData.Description"  />
                            <input type="text" id="hidSpectRefno" class="form-control" ng-model="myData.id" />

                         <ul style="height:300px; overflow-y:scroll; float:left;" id="ulS" >

                             <li ng-repeat="fav in myData" value="{{fav.id}}" >
                                    {{fav.Description}} 
                                </li>

                         </ul>

                      </div>
                      <div class="modal-footer">
                      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                      <button type="submit" id="btnSubmit"  class="btn btn-primary">Save changes</button>
                    </div>


                  </div><!-- /.modal-content -->
                </div><!-- /.modal-dialog -->

              </div><!-- /.modal -->
            </form>


<script type="text/javascript" >
    $(document).ready(function () {

        $("#ulS").on("click", "li", function () {
            $("#hidDescription").val($(this).text());
            $("#hidId").val($(this).val());
        });
        });

 </script>

1 个答案:

答案 0 :(得分:0)

我设法通过在

  • 上点击ng并在click事件中传递favorites对象来实现这一点。可能是范围。

    <ul style="height:300px; overflow-y:scroll; float:left;" id="ul" >
    <li ng-repeat="fav in favourites" value="{{fav.Refno}}"  ng-model="fav.Refno" ng-click="InsertFavourite(fav)">
    {{fav.Description}} 
    </li>
    </ul>