我只是試圖設置一個警告對話框,並試用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">×</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值!
你是怎麼做的要求?我猜測Angular沒有意識到vm模型中的變化,並且視圖沒有被更新。嘗試在切換模式之前使用$ apply()啓動摘要循環。 – Bema 2014-10-10 16:45:21
@Bema,如果我發出$ scope。$ apply();那麼錯誤說「$摘要已在進行中」。 – 2014-10-10 18:39:22