diff --git a/src/@fuse/components/navigation/navigation.component.ts b/src/@fuse/components/navigation/navigation.component.ts index 82a2409c..a133a35d 100644 --- a/src/@fuse/components/navigation/navigation.component.ts +++ b/src/@fuse/components/navigation/navigation.component.ts @@ -1,4 +1,8 @@ -import { Component, Input, ViewEncapsulation } from '@angular/core'; +import { Component, Input, OnInit, ViewEncapsulation } from '@angular/core'; +import { Subject } from 'rxjs'; +import { takeUntil } from 'rxjs/operators'; + +import { FuseNavigationService } from '@fuse/components/navigation/navigation.service'; @Component({ selector : 'fuse-navigation', @@ -6,7 +10,7 @@ import { Component, Input, ViewEncapsulation } from '@angular/core'; styleUrls : ['./navigation.component.scss'], encapsulation: ViewEncapsulation.None }) -export class FuseNavigationComponent +export class FuseNavigationComponent implements OnInit { @Input() layout = 'vertical'; @@ -14,11 +18,37 @@ export class FuseNavigationComponent @Input() navigation: any; + // Private + private _unsubscribeAll: Subject; + /** * Constructor */ - constructor() + constructor( + private _fuseNavigationService: FuseNavigationService + ) { + // Set the private defaults + this._unsubscribeAll = new Subject(); + } + // ----------------------------------------------------------------------------------------------------- + // @ Lifecycle hooks + // ----------------------------------------------------------------------------------------------------- + + /** + * On init + */ + ngOnInit(): void + { + // Load the navigation either from the input or from the service + this.navigation = this.navigation || this._fuseNavigationService.getCurrentNavigation(); + + // Subscribe to the current navigation changes + this._fuseNavigationService.onNavigationChanged + .pipe(takeUntil(this._unsubscribeAll)) + .subscribe((key) => { + this._fuseNavigationService.getNavigation(key); + }); } } diff --git a/src/app/layout/components/navbar/navbar.component.html b/src/app/layout/components/navbar/navbar.component.html index 037d9c58..115b1902 100644 --- a/src/app/layout/components/navbar/navbar.component.html +++ b/src/app/layout/components/navbar/navbar.component.html @@ -23,7 +23,7 @@ @@ -33,7 +33,7 @@ \ No newline at end of file