Created
August 26, 2019 13:43
-
-
Save BetterProgramming/ab734c1bd98b36ce11eb73c4c941aa18 to your computer and use it in GitHub Desktop.
This file contains 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, HostListener } from '@angular/core'; | |
import { Store, select } from '@ngrx/store'; | |
import { TOGGLE_MENU } from './reducers/menu-reducer'; | |
@Component({ | |
selector: 'app-root', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'] | |
}) | |
export class AppComponent { | |
menuOpen: boolean; | |
constructor( | |
private store: Store<any>, | |
) { | |
store.pipe(select('menu')) | |
.subscribe(menuOpen => { | |
this.menuOpen = menuOpen; | |
}) | |
} | |
@HostListener('document:click', ['$event']) | |
public onClick(event) { | |
const isOutside = !event.target.className.includes("menu-button") && | |
!event.target.className.includes("material-icons") && | |
!event.target.className.includes("mat-drawer-inner-container") | |
if (isOutside) { | |
this.menuOpen = false; | |
this.store.dispatch({ type: TOGGLE_MENU, payload: this.menuOpen }); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment