diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 30f8f928..3a0d4fbb 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -16,6 +16,7 @@ import { UIModule } from './main/content/ui/ui.module'; import { ComponentsModule } from './main/content/components/components.module'; import { FuseSplashScreenService } from './core/services/splash-screen.service'; import { FuseConfigService } from './core/services/config.service'; +import { FuseNavigationService } from './core/components/navigation/navigation.service'; import { ComponentsThirdPartyModule } from './main/content/components-third-party/components-third-party.module'; import { ServicesModule } from './main/content/services/services.module'; @@ -80,7 +81,8 @@ const appRoutes: Routes = [ ], providers : [ FuseSplashScreenService, - FuseConfigService + FuseConfigService, + FuseNavigationService ], bootstrap : [ AppComponent diff --git a/src/app/core/components/navigation/navigation.component.ts b/src/app/core/components/navigation/navigation.component.ts index 20f71ab7..837363dc 100644 --- a/src/app/core/components/navigation/navigation.component.ts +++ b/src/app/core/components/navigation/navigation.component.ts @@ -1,5 +1,6 @@ -import { Component, Input, ViewEncapsulation } from '@angular/core'; +import { Component, Input, OnDestroy, ViewEncapsulation } from '@angular/core'; import { FuseNavigationService } from './navigation.service'; +import { Subscription } from 'rxjs/Subscription'; @Component({ selector : 'fuse-navigation', @@ -7,15 +8,27 @@ import { FuseNavigationService } from './navigation.service'; styleUrls : ['./navigation.component.scss'], encapsulation: ViewEncapsulation.None }) -export class FuseNavigationComponent +export class FuseNavigationComponent implements OnDestroy { navigationModel: any[]; + navigationModelChangeSubscription: Subscription; @Input('layout') layout = 'vertical'; - constructor(private navigationService: FuseNavigationService) + constructor(private fuseNavigationService: FuseNavigationService) { - this.navigationModel = navigationService.getNavigationModel(); + this.navigationModelChangeSubscription = + this.fuseNavigationService.onNavigationModelChange + .subscribe((navigationModel) => { + console.warn(navigationModel); + this.navigationModel = navigationModel; + }); + } + + ngOnDestroy() + { + console.warn('destroyed'); + this.navigationModelChangeSubscription.unsubscribe(); } } diff --git a/src/app/core/components/navigation/navigation.service.ts b/src/app/core/components/navigation/navigation.service.ts index 4f9b6cc7..8a8e06d0 100644 --- a/src/app/core/components/navigation/navigation.service.ts +++ b/src/app/core/components/navigation/navigation.service.ts @@ -1,16 +1,19 @@ import { EventEmitter, Injectable } from '@angular/core'; import { NavigationModel } from '../../../navigation.model'; +import { BehaviorSubject } from 'rxjs/BehaviorSubject'; @Injectable() export class FuseNavigationService { onNavCollapseToggled = new EventEmitter(); + onNavigationModelChange: BehaviorSubject = new BehaviorSubject({}); navigationModel: NavigationModel; flatNavigation: any[] = []; constructor() { this.navigationModel = new NavigationModel(); + this.onNavigationModelChange.next(this.navigationModel.model); } /** @@ -22,6 +25,21 @@ export class FuseNavigationService return this.navigationModel.model; } + /** + * Set the navigation model + * @param model + */ + setNavigationModel(model) + { + // console.log(model); + + this.navigationModel = model; + + console.log(this.navigationModel); + + this.onNavigationModelChange.next(this.navigationModel.model); + } + /** * Get flattened navigation array * @param navigationItems @@ -41,7 +59,7 @@ export class FuseNavigationService continue; } - if ( navItem.type === 'nav-item' ) + if ( navItem.type === 'item' ) { this.flatNavigation.push({ title: navItem.title, @@ -53,7 +71,7 @@ export class FuseNavigationService continue; } - if ( navItem.type === 'nav-collapse' ) + if ( navItem.type === 'collapse' || navItem.type === 'group' ) { this.getFlatNavigation(navItem.children); } diff --git a/src/app/core/modules/shared.module.ts b/src/app/core/modules/shared.module.ts index 93885da7..8e83073b 100644 --- a/src/app/core/modules/shared.module.ts +++ b/src/app/core/modules/shared.module.ts @@ -12,7 +12,6 @@ import { FuseMdSidenavHelperDirective, FuseMdSidenavTogglerDirective } from '../ import { FusePipesModule } from '../pipes/pipes.module'; import { FuseConfirmDialogComponent } from '../components/confirm-dialog/confirm-dialog.component'; import { FuseCountdownComponent } from '../components/countdown/countdown.component'; -import { FuseNavigationService } from '../components/navigation/navigation.service'; import { FuseMatchMedia } from '../services/match-media.service'; import { FuseNavbarVerticalService } from '../../main/navbar/vertical/navbar-vertical.service'; import { FuseMdSidenavHelperService } from '../directives/md-sidenav-helper/md-sidenav-helper.service'; @@ -70,7 +69,6 @@ import { CookieService } from 'ngx-cookie-service'; ], providers : [ CookieService, - FuseNavigationService, FuseMatchMedia, FuseNavbarVerticalService, FuseMdSidenavHelperService