Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 405b9b17

Přidáno uživatelem Hung Hoang před téměř 6 roky(ů)

Menu component correctly chooses menu item to highlight

Zobrazit rozdíly:

webapp/src/app/menu/menu.component.ts
19 19
  ngOnInit() {
20 20
    this.menuService.getMenuItems()
21 21
      .subscribe((data: MenuItem[]) => {
22
        this.setMenuItems(data);
22
        this._menuItems = data;
23
        this._selectedMenuItem = this._menuItems[0];
24
        const path = this.location.path().split('/');
25
        const endOfPath = path[path.length - 1];
26

  
27
        this.setCorrectItemMenu(endOfPath);
23 28
      });
24 29
  }
25 30

  
26 31
  onSelect(menuItem: MenuItem): void {
27
    this._selectedMenuItem = menuItem;
28 32
    this.menuService.getMenuItems(true)
29
      .subscribe((menuItems: MenuItem[]) => this.setMenuItems(menuItems));
33
      .subscribe((menuItems: MenuItem[]) => {
34
        this._menuItems = menuItems;
35
        this.setCorrectItemMenu(menuItem.routePath);
36
      });
30 37
  }
31 38

  
32
  private setMenuItems(data: MenuItem[]) {
33
    this._menuItems = data;
34

  
35
    this._selectedMenuItem = this._menuItems[0];
36
    const path = this.location.path().split('/');
37
    const endOfPath = path[path.length - 1];
38

  
39
  private setCorrectItemMenu(routePath: string) {
39 40
    for (const item of this._menuItems) {
40
      if (item.routePath === endOfPath) {
41
      if (item.routePath === routePath) {
41 42
        this._selectedMenuItem = item;
42 43
      }
43 44
    }

Také k dispozici: Unified diff