Bootstrap模式对话框和Angular绑定无法正常工作

时间:2014-10-10 16:25:43

标签: angularjs twitter-bootstrap

我只是想设置一个警告对话框,并为初学者尝试Bootstrap模式。

Bootstrap模态:http://getbootstrap.com/javascript/#modals

模态会触发,但它不会显示我的modalTitle和modalBody值!

HTML片段(请注意vm.modalTitle和vm.modalBody范围变量) -

<!-- Bootstrap Modal Dialog Template-->
<div class="modal fade" id="myModal" 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"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
            <h4 class="modal-title" id="myModalLabel"><span ng-model="vm.modalTitle"></span></h4>
        </div>
        <div class="modal-body"><span ng-model="vm.modalBody"></span></div>
        <div class="modal-footer">
           <button type="button" class="btn btn-primary" data-dismiss="modal">OK</button>
        </div>
    </div>
</div>

和我的控制器代码:

 vm.modalTitle = '';   vars initialized at the top of my controller
 vm.modalBody = '';
 ...
 function sendRequest(){
      if (data.status == 'FAIL') {
                if (data.messages.length > 0) {
                    logErr("Error submitting aggregation request: " + data.messages[0]);
                    vm.modalTitle = "Error submitting aggregation query !";
                    vm.modalBody = data.messages[0];
                    $('#myModal').modal('toggle');  
                    $('#myModal').on('hide.bs.modal', function (e) {
                        // fired when modal is hidden from user
                    })
                    return;
                }
     }
   }

模态会触发,但它不会显示我的modalTitle和modalBody值!

1 个答案:

答案 0 :(得分:2)

当我第一次学习Angular的时候,我尝试过这条路线,并且很快就对为了让它工作而必须做的黑客感到沮丧。最好的办法是使用AngularUI模式。它很好地包裹了Bootstrap模态。 http://angular-ui.github.io/bootstrap/