2

Using a framework (materialize-css) it suggests me to put the following inside '$( document ).ready(function(){})' to get the responsive collapsable menu working:

$(".button-collapse").sideNav();

How would i do this in angular? I know that ngAfterContentInit is similar to '$( document ).ready(function(){})':

ngAfterContentInit(): void {
    //What do I put here?
  }

Below you can see a screenshot wich shows the hamburger icon (that becomes visible only on mobile screen sizes): Image of my menu

Here's my html (app.component.html):

<nav>
  <div class="nav-wrapper">
    <a href="#!" class="brand-logo">Logo</a>
    <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
    <ul class="right hide-on-med-and-down">
      <li><a href="sass.html">Sass</a></li>
      <li><a href="badges.html">Components</a></li>
      <li><a href="collapsible.html">Javascript</a></li>
      <li><a href="mobile.html">Mobile</a></li>
    </ul>
    <ul class="side-nav" id="mobile-demo">
      <li><a href="sass.html">Sass</a></li>
      <li><a href="badges.html">Components</a></li>
      <li><a href="collapsible.html">Javascript</a></li>
      <li><a href="mobile.html">Mobile</a></li>
    </ul>
  </div>
</nav>

1 Answers1

1

After some more research and trying out alternative tags on stackoverflow , I've found the perfect answer!

I have to make sure jquery is installed and angular-cli.json has the jquery node-module reference included at the very start !!

In my app.component.ts i had only to declare '$' as any.

Link to the answer: https://stackoverflow.com/a/42295505/7018180

Community
  • 1
  • 1