javascript - angular2 and materializecss integration - Stack Overflow

I am using angular2 to build a web app which uses HashLocationStrategy.everything is fine until I try

I am using angular2 to build a web app which uses HashLocationStrategy. everything is fine until I try to add materializecss jquery-based ponents to my templates.

for example here is a sample of navbar collapse button

<a href="#" data-activates="nav-mobile" class="button-collapse">
    <i class="material-icons">menu</i>
</a>

angular will treat this as a route path and will navigate to the main page

is there any work-rounds for this problem?

I am using angular2 to build a web app which uses HashLocationStrategy. everything is fine until I try to add materializecss jquery-based ponents to my templates.

for example here is a sample of navbar collapse button

<a href="#" data-activates="nav-mobile" class="button-collapse">
    <i class="material-icons">menu</i>
</a>

angular will treat this as a route path and will navigate to the main page

is there any work-rounds for this problem?

Share Improve this question asked Apr 29, 2016 at 17:54 alobaaloba 511 silver badge3 bronze badges 2
  • 1 Maybe just remove the href="#"? – André Kool Commented Apr 29, 2016 at 18:02
  • the button is not working when i remove href="#" and i don't know why? – aloba Commented Apr 30, 2016 at 9:27
Add a ment  | 

1 Answer 1

Reset to default 7

As you said it yourself: materializecss is jquery-based, i.e. it needs jquery to activate the dynamic behaviour. In your case, you'd have to add $(".button-collapse").sideNav(); somewhere in your page's $( document ).ready(function(){}) code.

Take a look at https://www.npmjs./package/angular2-materialize. This lib adds exactly this dynamic behaviour to angular2. After importing 'MaterializeDirective' in your angular2 ponent, you can simply add materialize="sideNav" to your anchor-tag and it should work:

<a href="#" materialize="sideNav" data-activates="nav-mobile" class="button-collapse">
  <i class="material-icons">menu</i>
</a>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744202812a4562962.html

相关推荐

  • javascript - angular2 and materializecss integration - Stack Overflow

    I am using angular2 to build a web app which uses HashLocationStrategy.everything is fine until I try

    8天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信