Skip to content

Instantly share code, notes, and snippets.

@GlinZachariah
Created November 7, 2019 02:06
Show Gist options
  • Save GlinZachariah/aba9736b0d14220924fb857ba8d4ffc4 to your computer and use it in GitHub Desktop.
Save GlinZachariah/aba9736b0d14220924fb857ba8d4ffc4 to your computer and use it in GitHub Desktop.
Angular Material - Responsive Web Page Format
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