Projekt

Obecné

Profil

Stáhnout (1.15 KB) Statistiky
| Větev: | Tag: | Revize:
1 4bd9d9f6 Hung Hoang
import {Component, OnInit} from '@angular/core';
2
import {MenuItem} from '../models/menu-item.model';
3
import {Location, LocationStrategy, PathLocationStrategy} from '@angular/common';
4
import {MenuService} from '../services/util/menu.service';
5 fd5ab42e Hung Hoang
6 0d1b0550 Václav Jirák
@Component({
7
  selector: 'app-menu',
8
  templateUrl: './menu.component.html',
9 4bd9d9f6 Hung Hoang
  styleUrls: ['./menu.component.sass'],
10
  providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}]
11 0d1b0550 Václav Jirák
})
12
export class MenuComponent implements OnInit {
13 79d7de40 Hung Hoang
  _menuItems: MenuItem[];
14
  private _selectedMenuItem: MenuItem;
15 0d1b0550 Václav Jirák
16 4bd9d9f6 Hung Hoang
  constructor(private location: Location, private menuService: MenuService) {
17 fd5ab42e Hung Hoang
  }
18 0d1b0550 Václav Jirák
19 fd5ab42e Hung Hoang
  ngOnInit() {
20 4bd9d9f6 Hung Hoang
    this.menuService.getMenuItems()
21
      .subscribe((data: MenuItem[]) => {
22
        this._menuItems = data;
23
24
        this._selectedMenuItem = this._menuItems[0];
25
        const path = this.location.path().split('/');
26
        const endOfPath = path[path.length - 1];
27
28
        for (const item of this._menuItems) {
29
          if (item.routePath === endOfPath) {
30
            this._selectedMenuItem = item;
31
          }
32
        }
33
      });
34 0d1b0550 Václav Jirák
  }
35
36
  onSelect(menuItem: MenuItem): void {
37 79d7de40 Hung Hoang
    this._selectedMenuItem = menuItem;
38 0d1b0550 Václav Jirák
  }
39
}