Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5b862e59

Přidáno uživatelem Hung Hoang před asi 6 roky(ů)

Re #7263 Created simple menu with a service and mock data

Zobrazit rozdíly:

frontend/src/app/app.component.html
8 8
  </div>
9 9
  <div class="row content">
10 10
    <div class="col-lg-2 navigation">
11
      <nav class="navbar">
12
        <ul class="navbar-nav">
13
          <li *ngFor="let item of menuItems; let i = index" class="nav-item selected">
14
            <a href="#">{{i}} {{item}}</a>
15
          </li>
16
        </ul>
17
      </nav>
11
      <app-menu></app-menu>
18 12
    </div>
19 13
    <div class="col-lg-7">seamless</div>
20 14
    <div class="col-lg-3">mas</div>
frontend/src/app/app.component.sass
32 32
  background-color: #2F313F
33 33
  margin: 0
34 34
  padding: 0
35

  
36

  
37
.navbar
38
  width: 100%
39
  margin: 0
40
  padding: 0
41

  
42
.navbar-nav
43
  width: 100%
44

  
45
.nav-bar
46
  width: 100%
47

  
48
.nav-item
49
  height: 50px
50
  line-height: 50px
51
  width: 100%
52
  padding-left: 20px
53
  color: #404353
54
  background-color: #2F313F
55
  border-style: solid
56
  border-width: 0 0 1px 0
57
  border-color: #6D6F81
58

  
59
  &:hover
60
    background-color: #414356
61

  
62
  a
63
    color: #6D6F81
64
    width: 100%
65
    height: 100%
66

  
67

  
68
.nav-item.selected
69
  background-color: #63AA22
70

  
71
  a
72
    color: white
73

  
74
  &:hover
75
    background-color: #7ad129
76

  
frontend/src/app/app.module.ts
4 4
import { AppRoutingModule } from './app-routing.module';
5 5
import { AppComponent } from './app.component';
6 6
import {HttpClientModule} from '@angular/common/http';
7
import { MenuComponent } from './menu/menu.component';
7 8

  
8 9
@NgModule({
9 10
  declarations: [
10
    AppComponent
11
    AppComponent,
12
    MenuComponent
11 13
  ],
12 14
  imports: [
13 15
    BrowserModule,
frontend/src/app/menu.service.ts
1
import { Injectable } from '@angular/core';
2
import { MenuItem } from './menu/menuItem';
3
import { Observable, of } from 'rxjs';
4
import { MENU_ITEMS } from './mock-menu-items';
5

  
6
@Injectable({
7
  providedIn: 'root'
8
})
9
export class MenuService {
10

  
11
  getMenuItems(): Observable<MenuItem[]> {
12
    return of(MENU_ITEMS);
13
  }
14

  
15
  constructor() { }
16
}
frontend/src/app/menu/menu.component.html
1
<div class="navigation">
2
  <nav class="navbar">
3
    <ul class="navbar-nav">
4
      <li *ngFor="let item of menuItems; let i = index" class="nav-item selected">
5
        <a href="#">{{item.name}}</a>
6
      </li>
7
    </ul>
8
  </nav>
9
</div>
frontend/src/app/menu/menu.component.sass
1
.navbar
2
  width: 100%
3
  margin: 0
4
  padding: 0
5

  
6
.navbar-nav
7
  width: 100%
8

  
9
.nav-bar
10
  width: 100%
11

  
12
.nav-item
13
  height: 50px
14
  line-height: 50px
15
  width: 100%
16
  padding-left: 20px
17
  color: #404353
18
  background-color: #2F313F
19
  border-style: solid
20
  border-width: 0 0 1px 0
21
  border-color: #6D6F81
22

  
23
  &:hover
24
    background-color: #414356
25

  
26
  a
27
    color: #6D6F81
28
    width: 100%
29
    height: 100%
30

  
31

  
32
.nav-item.selected
33
  background-color: #63AA22
34

  
35
  a
36
    color: white
37

  
38
  &:hover
39
    background-color: #7ad129
frontend/src/app/menu/menu.component.ts
1
import { Component, OnInit } from '@angular/core';
2
import { MenuService } from '../menu.service';
3
import { MenuItem } from './menuItem';
4

  
5
@Component({
6
  selector: 'app-menu',
7
  templateUrl: './menu.component.html',
8
  styleUrls: ['./menu.component.sass']
9
})
10
export class MenuComponent implements OnInit {
11
  menuItems: MenuItem[];
12

  
13

  
14
  getMenuItems(): void {
15
    this.menuService.getMenuItems()
16
      .subscribe(menuItems => this.menuItems = menuItems);
17
  }
18

  
19
  constructor(private menuService: MenuService) { }
20

  
21
  ngOnInit() {
22
    this.getMenuItems();
23
  }
24

  
25

  
26
}
frontend/src/app/menu/menuItem.ts
1
export class MenuItem {
2
  name: string;
3
}
frontend/src/app/mock-menu-items.ts
1
import { MenuItem } from './menu/menuItem';
2

  
3
export const MENU_ITEMS: MenuItem[] = [
4
  {name: 'Dashboard'},
5
  {name: 'Zamestnanci'},
6
];

Také k dispozici: Unified diff