0

I generated a header component using ng generate @angular/material:material-nav --name header, in this I need to have the hamburger icon fixed even if the screen size is larger. Right now it appears only when screen size is small. I need some help in fixing this. Code in stackblitz (https://angular-bfjx3s.stackblitz.io/) Thank you

Need something like this (https://console.cloud.google.com)

PremKumar
  • 1,282
  • 4
  • 25
  • 43

4 Answers4

1

Remove the *ngIf condition from below code in header.component.html

<button
  type="button"
  aria-label="Toggle sidenav"
  mat-icon-button
  (click)="drawer.toggle()">
  <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
</button>
SuperStar518
  • 2,814
  • 2
  • 20
  • 35
nitin9nair
  • 580
  • 3
  • 12
1

You can remove the conditional statement *ngIf="isHandset$ | async" from button

NIDHIN VINCENT
  • 225
  • 1
  • 2
  • 9
1

You need to change *ngIf condition for the hamburger button like this (or you could even remove *ngIf if you want the button to be always visible:

<mat-toolbar color="primary">
      <button
        type="button"
        aria-label="Toggle sidenav"
        mat-icon-button
        (click)="drawer.toggle()"
        *ngIf="true">
        <mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
      </button>
      <span>web-doctor</span>
  </mat-toolbar>

The code here: https://stackblitz.com/edit/angular-kutmnh

Sebastian Denis
  • 928
  • 10
  • 20
  • Thank you,on doing that the toolbar moves to the right now and the backdrop is not working. For smaller screen size the backdrop is working, which means I can click any where on the screen and the hamburger icon collapses. – PremKumar Jun 24 '19 at 06:20
1

Thank you everyone for trying, I found that are different breakpoints as mentioned here (Angular mat-sidenav property isHandset$ | async explain) So I changed current settings to ((isWeb$ | async) || (isTablet$ | async) || (isHandSet$ | async)) in HTML file and in TS file as follows

 isWeb$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Web)
    .pipe(
      map(result => result.matches)
    );

    isTablet$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Tablet)
    .pipe(
      map(result => result.matches)
    );

    isHandSet$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
    .pipe(
      map(result => result.matches)
    );
PremKumar
  • 1,282
  • 4
  • 25
  • 43