fix(menu): fix #84 page title and breadcrumb not showing up

This commit is contained in:
nixa 2016-07-14 12:05:05 +03:00
parent 77a13b5308
commit 8340acec7a
2 changed files with 27 additions and 4 deletions

View file

@ -5,6 +5,7 @@ import {Subscription} from 'rxjs/Rx';
import {BaSlimScroll} from '../../../theme/directives';
import {BaMenuService} from './baMenu.service';
import {BaMenuItem} from './components/baMenuItem';
import {AppState} from '../../../app.state';
@Component({
selector: 'ba-menu',
@ -29,15 +30,27 @@ export class BaMenu {
protected _onRouteChange:Subscription;
public outOfArea:number = -200;
constructor(private _router:Router, private _service:BaMenuService) {
constructor(private _router:Router, private _service:BaMenuService, private _state:AppState) {
this._onRouteChange = this._router.events.subscribe((event) => {
if (this.menuItems && event instanceof NavigationEnd) {
this.menuItems = this._service.selectMenuItem(this.menuItems);
if (event instanceof NavigationEnd) {
if (this.menuItems) {
this.selectMenuAndNotify();
} else {
// on page load we have to wait as event is fired before menu elements are prepared
setTimeout(() => this.selectMenuAndNotify());
}
}
});
}
public selectMenuAndNotify():void {
if (this.menuItems) {
this.menuItems = this._service.selectMenuItem(this.menuItems);
this._state.notifyDataChanged('menu.activeLink', this._service.getCurrentItem());
}
}
public ngOnInit():void {
this.menuItems = this._service.convertRoutesToMenus(this.menuRoutes);
}

View file

@ -4,6 +4,8 @@ import {Router, UrlTree, RouterConfig} from '@angular/router';
@Injectable()
export class BaMenuService {
protected _currentMenuItem = {};
constructor(private _router:Router) {
}
@ -12,11 +14,19 @@ export class BaMenuService {
return this._skipEmpty(items);
}
public getCurrentItem():any {
return this._currentMenuItem;
}
public selectMenuItem(menuItems:any[]):any[] {
let items = [];
menuItems.forEach((item) => {
this._selectItem(item);
if (item.selected) {
this._currentMenuItem = item;
}
if (item.children && item.children.length > 0) {
item.children = this.selectMenuItem(item.children);
}