2016-06-09 22 views
0

如果我在模態內調用$("#modal").closeModal();,則不會觸發complete方法。我打開以下模式。實現closeModal不發射完成

$("#modal").openModal({ 
    dismissible: false, 
    complete: this.doSomething 
}); 

有什麼我做錯了嗎?有沒有辦法觸發模態在模態內部關閉,以便觸發complete方法?我需要等待模式關閉之前發生的事情。

+0

這是如何相關Angular2?如果它實際上是請添加更多的上下文。你在哪裏以及如何在Angular2中使用它? –

回答

1

這是你想要的嗎?

HTML文件

<!-- Modal Structure --> 
<a class="waves-effect waves-light btn modal-trigger" href="#modal1">Modal</a> 

<div id="modal1" class="modal"> 
    <div class="modal-content"> 

    <!--following line has the icon to close the modal on your command--> 

    <h4>Modal Header <i class = "material-icons right" id = "closeIcon">close</i></h4> 
    <p>A bunch of text</p> 

    <!--following button adds text to the <p> tag with id = "textBody" i.e. its doing something and the modal wont close until that is done--> 

    <button class = "btn waves-effect waves-light" id = "doSomething">Press me and do something</button> 


    </div> 
    <div class="modal-footer"> 
    <a href="#!" class=" modal-action modal-close waves-effect waves-green btn-flat">Agree</a> 
    </div> 
</div> 
<p id = "textBody"> 

</p> 

jQuery的

$(document).ready(function(){ 
    $('.modal-trigger').leanModal({ 
    dismissible: false, 

    /*waiting for the user to click the button before closing*/ 
    complete: $('#doSomething').click(function(){   

        $('#textBody').html('i got a Boo Boo'); 
        $('#modal1').closeModal();      

       })   

    }); 
    $("#closeIcon").click(function(){ 
    $('#modal1').closeModal(); 
    }); 



}) 

這裏是檢查發生了什麼鏈接:https://jsfiddle.net/4y6ptm8k/4/

+0

不好意思把這個備份起來,但是有沒有辦法通過調用closeModal而不是通過用戶輸入來嚴格激發整個事件?我用盡谷歌,並沒有找到一個解決方案。 – IRCraziestTaxi

+0

@IRCraziestTaxi您希望事件發生在'closeModal()'函數內? – hulkinBrain