2015-11-27 38 views
0

:莫代爾,如何動態地關閉彈出模態(UI自舉),而點擊事件Angularjs

<script type="text/ng-template" id="create.html"> 
<div ng-controller="CreateCampaignCtrl" id="createModal"> 
    <div class="modal-header"> 
     heading 
    </div> 
    <div class="modal-body"> 
     ---- 
    </div> 
    <div class="modal-footer"> 
     <button type="button" class="btn btn-white" ng-click="cancel()">Close</button> 
     <button type="button" class="btn btn-primary" ng-click="submit_form()"><i class="fa fa-plus"></i>create method</button> 
    </div> 
</div> 

:控制器

function CreateCampaignCtrl($scope, $http){  
$scope.submit_form = function(){ 
     $http({ 
      url: url, 
      data: {}, 
      method: "POST", 
      headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} 
     }).success(function(data){ 
       $('#createModal').modal('hide'); 
       alert(data); 
     }).error(function(err) { alert('ERROR err');}) 
    } 
}; 

};

上面的模式是在點擊按鈕時打開ajax請求,現在我想在從服務器獲得響應後動態關閉此模式。

+0

爲什麼不試試'角度控制器代碼中的'$ modalInstanse.close()'? –

+0

你好Pankaj,我嘗試過使用這種方法,但它不工作。感謝您的答覆。 –

+0

你使用'angular-ui-bootstrap'/jQuery'bootstrap'模式嗎? –

回答

0

編輯:

好的報廢我的第一個想法。它的確如此簡單

modalInstance.close() 

我剛創建了一個2秒的超時來模擬您的承諾。

$timeout(function(){modalInstance.close();},2000); 

plunker here

+0

你好李,感謝您的回覆,我嘗試使用$('#id).modal('close')它不關閉模式,而是它導致錯誤。 –

+0

@VenkateshS不認爲你可以提供錯誤? –

+0

TypeError:data [option]不是函數 –

0

最後我得到的解決方案,以便UI-POP引導-UP模態在angularjs:

function getRetiredData($scope, $http, $modalStack){ 
    $http({ 
     url : base_url, 
     data : {}, 
     method : "POST", 
     headers : {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'} 
    }).success(function(data){ 
     $modalStack.dismissAll(); 
    }).error(function(err){ 
     alert(err); 
    }); 
}; 

};

在你的控制器中注入$ modalStack並調用這個函數$ modalStack.dismissAll();它關閉所有打開的模態。

相關問題