diff --git a/src/@fuse/components/sidebar/sidebar.service.ts b/src/@fuse/components/sidebar/sidebar.service.ts index a1da4cbb..c101b56c 100644 --- a/src/@fuse/components/sidebar/sidebar.service.ts +++ b/src/@fuse/components/sidebar/sidebar.service.ts @@ -58,7 +58,7 @@ export class FuseSidebarService * * @param key */ - getSidebar(key): any + getSidebar(key): FuseSidebarComponent { // Check if the sidebar exists if ( !this._registry[key] ) diff --git a/src/app/main/navbar/navbar.component.html b/src/app/main/navbar/navbar.component.html index cdaab1a1..d59ee113 100644 --- a/src/app/main/navbar/navbar.component.html +++ b/src/app/main/navbar/navbar.component.html @@ -10,12 +10,12 @@ diff --git a/src/app/main/navbar/navbar.component.ts b/src/app/main/navbar/navbar.component.ts index 78114850..7889d66d 100644 --- a/src/app/main/navbar/navbar.component.ts +++ b/src/app/main/navbar/navbar.component.ts @@ -1,4 +1,5 @@ -import { Component, Input, OnDestroy, ViewChild, ViewEncapsulation } from '@angular/core'; +import { Component, Input, OnDestroy, OnInit, ViewChild, ViewEncapsulation } from '@angular/core'; +import { NavigationEnd, Router } from '@angular/router'; import { Subscription } from 'rxjs/Subscription'; import { FusePerfectScrollbarDirective } from '@fuse/directives/fuse-perfect-scrollbar/fuse-perfect-scrollbar.directive'; @@ -13,7 +14,7 @@ import { FuseNavigationService } from '@fuse/components/navigation/navigation.se styleUrls : ['./navbar.component.scss'], encapsulation: ViewEncapsulation.None }) -export class FuseNavbarComponent implements OnDestroy +export class FuseNavbarComponent implements OnInit, OnDestroy { private fusePerfectScrollbar: FusePerfectScrollbarDirective; @@ -41,7 +42,8 @@ export class FuseNavbarComponent implements OnDestroy constructor( private sidebarService: FuseSidebarService, - private navigationService: FuseNavigationService + private navigationService: FuseNavigationService, + private router: Router ) { // Navigation data @@ -51,6 +53,18 @@ export class FuseNavbarComponent implements OnDestroy this.layout = 'vertical'; } + ngOnInit() + { + this.router.events.subscribe( + (event) => { + if ( event instanceof NavigationEnd ) + { + this.sidebarService.getSidebar('navbar').close(); + } + } + ); + } + ngOnDestroy() { if ( this.fusePerfectScrollbarUpdateTimeout ) @@ -64,13 +78,13 @@ export class FuseNavbarComponent implements OnDestroy } } - toggleSidebarOpened(key) + toggleSidebarOpened() { - this.sidebarService.getSidebar(key).toggleOpen(); + this.sidebarService.getSidebar('navbar').toggleOpen(); } - toggleSidebarFolded(key) + toggleSidebarFolded() { - this.sidebarService.getSidebar(key).toggleFold(); + this.sidebarService.getSidebar('navbar').toggleFold(); } }