Vertical side nav bar - Angular 4 and Bootstrap 3

25,279

First You need to Import bootstrap 3 or Use Bootstrap 3 CDN

Then Instead of using JQuery Use Directive to manipulate Class and Style of Side Bar

I Have Created Stack blitz for same side Bar without using JQuery Check this: https://stackblitz.com/edit/angular-z6hrob

Share:
25,279
VicentVega
Author by

VicentVega

Updated on August 07, 2020

Comments

  • VicentVega
    VicentVega almost 4 years

    I have installed bootstrap 3 in my angular 4 project using the npm installer. I have a basic site done up and am trying to get an dynamic sideNav bar that will toggle in and out.

    I have seen some examples online however they do not seem to work whether it be a newer version of bootstrap or compatibility issues with angular.

    Does anyone have any recommendations for a navigation bar that I could use in this instance?

    The HTML in my app.component.html:

    <!-- Sidebar -->
    <script src="src/Javascript/sidebar.js"></script>
    <nav class="navbar navbar-inverse navbar-fixed-left" id="sidebar-wrapper" role="navigation">
        <ul class="nav sidebar-nav">
            <li class="sidebar-brand">
                <a href="#">
                    Brand
                </a>
            </li>
            <li>
                <a href="#">Home</a>
            </li>
            <li>
                <a href="#">About</a>
            </li>
            <li>
                <a href="#">Events</a>
            </li>
            <li>
                <a href="#">Team</a>
            </li>
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    Works <span class="caret"></span>
                </a>
                <ul class="dropdown-menu" role="menu">
                    <li><a href="#">About</a></li>
                    <li><a href="#">Services</a></li>
                    <li><a href="#">Clients</a></li>
                    <li><a href="#">Contact</a></li>
                </ul>
            </li>
            <li>
                <a href="#">Services</a>
            </li>
            <li>
                <a href="#">Contact</a>
            </li>
        </ul>
    </nav>
    
  • Deepak Verma
    Deepak Verma almost 6 years
    are u using any npm module for it?
  • Chellappan வ
    Chellappan வ almost 6 years
    i am not using any npm module for this. only bootstrap
  • Deepak Verma
    Deepak Verma almost 6 years
    hmm what is this sidebar.directive.ts you have imported this in your app module file
  • Chellappan வ
    Chellappan வ almost 6 years
    that is angular directive which is used toggle bootstrap class when you click the icon
  • Deepak Verma
    Deepak Verma almost 6 years
    if you dont mind could you please come to chat room?
  • netalex
    netalex over 4 years
    please do not use jquery in your angular components
  • Chellappan வ
    Chellappan வ over 4 years
    I have not used JQuery
  • Rick O'Shea
    Rick O'Shea over 4 years
    ... and only 300 lines of cut-and-paste custom CSS. Anything this prolific should be a drop-in component with a few styles and a simple list of menu items and action callbacks.