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);
}