简体   繁体   English

Angular 2+实现jQuery

[英]Angular 2+ Materialize jquery

I am trying out Materialize in an Angular 4 project and it's all installed and working. 我正在Angular 4项目中试用Materialize,它已安装并正常工作。

My problem comes with I try the script section. 我的问题来自我尝试的脚本部分。

For example: 例如:

I add this to my component.html: 我将其添加到我的component.html中:

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

  <!-- Modal Structure -->
  <div id="modal1" class="modal">
    <div class="modal-content">
      <h4>Modal Header</h4>
      <p>A bunch of text</p>
    </div>
    <div class="modal-footer">
      <a href="#!" class="modal-action modal-close waves-effect waves-green btn-flat">Agree</a>
    </div>
  </div>

And then the instructions tell me to initialize it using jquery so I'm added this to my index.html: 然后说明告诉我使用jquery对其进行初始化,因此将其添加到index.html中:

<script>
  $(document).ready(function(){
    $('.modal1').modal();
  });
</script>

The problem I cannot see any modal appearing. 我看不到任何模态出现的问题。

How can I get this to work on Angular 4? 如何在Angular 4上使用它?

Try the following: 请尝试以下操作:

<script>
  $(document).ready(function(){
     $('.modal-trigger').leanModal();
  });
</script>

plunker plunker

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM