2017-01-26 125 views
0

我一直在尋找的論壇這個問題和解決方案爲我工作不到風度,所以......UI引導模式不關閉。 AngularJS

關閉模式的唯一方法是點擊模式的鍵盤上按ESC鍵之外,或..

這裏是我的模態控制器:

app.controller('ModalCtrl', function($scope, $uibModal) { 

     $scope.items = [{}] 


     $scope.showModal = function(selectedItem) { 

      var uibModalInstance = $uibModal.open({ 
      windowTopClass: 'modal fade ql-modal', 
      templateUrl : 'modalContent.html', 
      controller : function($scope, $uibModalInstance, $uibModal, item){ 
       $scope.item = item; 

      }, 
      resolve: { 
       item: function(){ 
        return selectedItem; 
       } 
      } // empty storage 
      }); 

      uibModalInstance.result.then(function(selectedItem){ 
      $scope.selected = selectedItem; 
      $scope.cancel = function(){ 
       $uibModalInstance.dismiss('cancel'); 
      }; 
      }); 
     };     
}); 

這裏是我的HTML模式:

<script type="text/ng-template" id="modalContent.html"> 
     <!-- Modal --> 
       <!--Content--> 
       <div class="modal-content"> 
        <!--Header--> 
        <div class="modal-header"> 
         <button type="button" class="close" data-dismiss="MyModal" aria-label="Close" ng-click="cancel()"> 
          <span aria-hidden="true">&times;</span> 
         </button> 

        ................................... 

         <div class="modal-footer"> 
         <button type="button" class="btn btn-primary" ng-click="cancel()">Close</button> 
        </div> 
       </div> 
       <!--/.Content--> 
     <!--/Modal--> 
    </script> 

我跟着每一個答案,小提琴,plnkr,但我不能讓它工作。

回答

1

只需動cancel()方法從uibModalInstance.result.then到 您的模態控制器:

var uibModalInstance = $uibModal.open({ 
     windowTopClass: 'modal fade ql-modal', 
     templateUrl : 'modalContent.html', 
     controller : function($scope, $uibModalInstance, $uibModal, item){ 
      $scope.item = item; 
      $scope.cancel = function(){ 
       $uibModalInstance.dismiss('cancel'); 
      }; 
     }, 
     resolve: { 
      item: function(){ 
       return selectedItem; 
      } 
     } // empty storage 
     }); 
+0

感謝。現在工作。 –