3

Im trying to build a progressive web-app with Angular and Bootstrap. The most challenging part is to implement a navbar that looks good on the web and on the mobile view. For the most part I'm pretty happy with my implementation so far. See Link on Stackblitz

But now I am trying to toggle the navbar as a Sidebar, that opens up from the right to the left. Additionally the sidebar should push the content (Placeholder-Text) to the left. This could be kind of tough, because that perhaps means modifying some Bootstrap classes. Maybe some of you have a solution for this. Currently my navbar toggles the links underneath.

html

<nav class="navbar navbar-expand-md navbar-dark bg-dark fixed-top">
  <ul class="navbar-nav">
    <li class="nav-item">
      <a class="navbar-brand d-none d-md-block" href="javascript:void(0)">
        <img alt="logo" src="https://..." width="40px" height="auto">
        My Brand
      </a>
    </li>
  </ul>

  <ul class="navbar-nav mr-auto mr-md-3">
    <li class="nav-item">
      <a class="nav-link font-weight-bold" href="javascript:void(0)">Stories</a>
    </li>
  </ul>

    <ul class="navbar-nav mr-auto mr-md-3">
      <li class="nav-item">
        <a class="nav-link" href="javascript:void(0)">
          <span>
            <img class="rounded" src="https://..." alt="user" width="35" height="35">
            <span class="d-none d-lg-inline">&nbsp; Tommy</span>
          </span>
        </a>
      </li>
    </ul>

    <ul class="navbar-nav mr-auto">
      <li class="nav-item">
        <a class="nav-link font-weight-bold" href="javascript:void(0)">
          <div class="img-container" (click)="notificationsViewed = true">
            <img alt="notifications" src="https://..." width="35">
            <span [hidden]="notificationsViewed" class="badge badge-danger notifications-count">{{3}}</span>
          </div>
        </a>
      </li>
    </ul>

  <button class="navbar-toggler" (click)="toggleNavbar()" type="button" [attr.aria-expanded]="!isCollapsed">
    <span class="icon-bar top-bar"></span>
    <span class="icon-bar middle-bar"></span>
    <span class="icon-bar bottom-bar"></span>
  </button>

  <div class="collapse navbar-collapse" [ngClass]="{ 'show': isCollapsed }">

    <ul class="navbar-nav float-right ml-auto">
      <li class="nav-item">
        <a class="nav-link font-weight-bold" href="javascript:void(0)">About Us</a>
      </li>
      <li class="nav-item">
        <a class="nav-link font-weight-bold"href="javascript:void(0)">Policy</a>
      </li>
      <li class="nav-item">
        <a class="nav-link font-weight-bold" href="javascript:void(0)">Contact</a>
      </li>
      <li class="nav-item">
        <button (click)="logout()" class="btn btn-bd-logout">
          Logout
        </button>
      </li>
    </ul>

  </div>
</nav>

Typescript

  public isCollapsed: boolean = false;

  toggleNavbar() {
    this.isCollapsed = !this.isCollapsed;
  }

1 Answer 1

2

I didn't understand second part the sidebar should push the content (Placeholder-Text) to the left.

But for the first part for Sidebar try using Angular Material Navigation Option :

Angular Material Sidenav

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.