Created
November 7, 2019 02:06
-
-
Save GlinZachariah/aba9736b0d14220924fb857ba8d4ffc4 to your computer and use it in GitHub Desktop.
Angular Material - Responsive Web Page Format
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, ViewChild, HostListener } from '@angular/core'; | |
import { MatSidenav } from '@angular/material/sidenav'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent { | |
opened = true; | |
@ViewChild('sidenav', { static: true }) sidenav: MatSidenav; | |
ngOnInit() { | |
console.log(window.innerWidth) | |
if (window.innerWidth < 768) { | |
this.sidenav.fixedTopGap = 55; | |
this.opened = false; | |
} else { | |
this.sidenav.fixedTopGap = 55; | |
this.opened = true; | |
} | |
} | |
@HostListener('window:resize', ['$event']) | |
onResize(event) { | |
if (event.target.innerWidth < 768) { | |
this.sidenav.fixedTopGap = 55; | |
this.opened = false; | |
} else { | |
this.sidenav.fixedTopGap = 55 | |
this.opened = true; | |
} | |
} | |
isBiggerScreen() { | |
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth; | |
if (width < 768) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment