Projekt

Obecné

Profil

Stáhnout (1.15 KB) Statistiky
| Větev: | Tag: | Revize:
1
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

    
6
@Component({
7
  selector: 'app-menu',
8
  templateUrl: './menu.component.html',
9
  styleUrls: ['./menu.component.sass'],
10
  providers: [Location, {provide: LocationStrategy, useClass: PathLocationStrategy}]
11
})
12
export class MenuComponent implements OnInit {
13
  _menuItems: MenuItem[];
14
  private _selectedMenuItem: MenuItem;
15

    
16
  constructor(private location: Location, private menuService: MenuService) {
17
  }
18

    
19
  ngOnInit() {
20
    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
  }
35

    
36
  onSelect(menuItem: MenuItem): void {
37
    this._selectedMenuItem = menuItem;
38
  }
39
}
(3-3/3)