enriquemaestre
enriquemaestre

Reputation: 1

window.innerWidth When I run this, the action is not performed

I am making a menu bar but window.innerWidth does not execute the action of collapsing the bar without covering the dashboard, that is, the dashboard is covered by the bar. I try to collapse the bar together with the dashboard, but the bar covers the dashboard. https://github.com/Opalo2289/sidenav.git


import { Component, EventEmitter, OnInit, Output } from '@angular/core';
import { navbarData } from './nav-data';

interface SideNavToggle {
  screenWidth: number;
  collapsed: boolean;
}

@Component({
  selector: 'app-sidenav',
  templateUrl: './sidenav.component.html',
  styleUrls: ['./sidenav.component.scss']
})
export class SidenavComponent implements OnInit {

  @Output() onToggleSidenav: EventEmitter<SideNavToggle> = new EventEmitter();
  collapsed = false;
  screenWidth = 0;
  navData = navbarData;

  constructor() { }

  ngOnInit(): void {
    this.screenWidth = window.innerWidth;
  }
  
  toggleCollapse(): void {
    this.collapsed = !this.collapsed;
    this.onToggleSidenav.emit({collapsed: this.collapsed, screenWidth: this.screenWidth})
  }

  closeSidenav(): void {
    this.collapsed = false;
    this.onToggleSidenav.emit({collapsed: this.collapsed, screenWidth: this.screenWidth})
  }

}

Upvotes: 0

Views: 31

Answers (0)

Related Questions