【问题标题】:Materialize closeModal not firing complete实现closeModal未触发完成
【发布时间】:2016-06-09 16:43:50
【问题描述】:

如果我在模态框内调用$("#modal").closeModal();,则不会触发complete 方法。我使用以下内容打开模式。

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

我做错了什么吗?有没有办法触发模态在模态内部关闭,从而触发complete方法?在模态关闭之前,我需要等待某些事情发生。

【问题讨论】:

  • 这与 Angular2 有什么关系?如果确实如此,请添加更多上下文。您在 Angular2 中的什么地方以及如何使用它?

标签: javascript html typescript angular materialize


【解决方案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/

【讨论】:

  • 很抱歉把这件事搞砸了,但是有没有办法严格通过调用 closeModal 而不是通过用户输入来触发完整的事件?我已经用尽了谷歌并没有找到解决方案。
  • @IRCraziestTaxi 您希望事件在closeModal() 函数中发生吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
  • 2015-04-14
  • 2013-05-20
  • 2012-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多