2016-09-07 20 views
1

我想弄清楚爲什麼這個特定的Bootstrap確認模式不能與我想要的功能一起工作。它似乎與一個基本功能一起提供了一個警告窗口,但是當我把它放到我想要的功能時,它執行該功能(在這種情況下,從File-stack和我的數據庫中刪除一個圖像),但它掛起了模式窗口到模式窗口關閉的地方,但是灰色疊加層卡住了,它使頁面不再起作用。似乎持有這個功能的功能是modal-footer div中的第一個按鈕。關閉按鈕工作正常,當我再次把一個簡單的函數來代替removeMoreImage()功能這裏的正常工作是代碼的引導模式:有角度的Bootstrap模態。莫代爾沒有關閉具體的數據ng鍵功能

 <button type="button" class="btn btn-danger" data-toggle="modal" data-target="#confirm-modal-more"> <span class= "glyphicon glyphicon-remove-circle"></span> REMOVE IMAGE</button> 

     <div id="confirm-modal-more" class="modal fade" role="dialog"> 
      <div class="modal-dialog"> 

      <div class="modal-content"> 
      <div class="modal-header"> 
       <button type="button" class="close" data-dismiss="modal">&times;</button> 
       <h4 class="modal-title">Remove Image Confirmation</h4> 
      </div> 
      <div class="modal-body"> 
       <p>Are you sure you want to delete this image?</p> 
      </div> 
      <div class="modal-footer"> 
       <button type="button" class="btn btn-danger" data-ng-click="removeMoreImage(picture.url, car)" data-dismiss="modal" >REMOVE</button> 
       <button type="button" class="btn btn-default" data-dismiss="modal">CANCEL</button> 
      </div> 
      </div> 

      </div> 
     </div> 

這裏是正在執行造成掛斷功能:

var getIndexIfObjWithOwnAttr = function(array, attr, value) { 
    for (var i = 0; i < array.length; i++) { 
     if (array[i].hasOwnProperty(attr) && array[i][attr] === value) { 
      return i; 
     } 
    } 
    return -1; 
} 

$scope.removeMoreImage = function(image, data) { 
    var index = getIndexIfObjWithOwnAttr(data.morePictures, 'url', image); 
    data.morePictures.splice(index, 1); 
    filepickerService.remove(image); 
    console.log(image + " has been removed!"); 
} 

任何見解或建議將是偉大的。這似乎是同步問題,但我不確定。

回答

0

我結束了使用一些查詢強制模式關閉,它似乎很好地工作,雖然它不像我希望的解決方案的優雅,但它似乎工作。這是我添加到懸掛模式的功能的代碼。

$('#confirm-modal-more').modal('hide'); 
$('body').removeClass('modal-open'); 
$('.modal-backdrop').remove(); 
0

您可以關閉的功能模式,並返回一個結果給父控制器:

$uibModalInstance.close('some result of modal'); 
$uibModalInstance.dismiss('some reason for discarding and closing'); 

$scope.removeMoreImage = function(image, data) { 
    var index = getIndexIfObjWithOwnAttr(data.morePictures, 'url', image); 
    data.morePictures.splice(index, 1); 
    filepickerService.remove(image); 
    console.log(image + " has been removed!"); 

    // close modal 
    $uibModalInstance.close(); 
} 

https://angular-ui.github.io/bootstrap/#/modal