File

src/app/main/containers/app/app.component.ts

Implements

OnInit

Metadata

selector app-root
styleUrls app.component.scss
templateUrl ./app.component.html

Index

Properties
Methods

Constructor

constructor(translate: TranslateService, store: Store)

Methods

closeIfSmall
closeIfSmall()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onSidenavClosed
onSidenavClosed()
Returns : void
onToggleSidenav
onToggleSidenav()
Returns : void
onWindowResize
onWindowResize(event: any)
Decorators : HostListener
Returns : void

Properties

isOpen
isOpen: boolean
Type : boolean
mode
mode: string
Type : string
showSidenav
showSidenav: Observable<boolean>
Type : Observable<boolean>
sidenavMode
sidenavMode: Observable<string>
Type : Observable<string>
viewList
viewList: Array<NavItem>
Type : Array<NavItem>
import { Component, HostListener, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { TranslateService } from '@ngx-translate/core';
import { Store } from '@ngrx/store';

import * as fromRoot from '../../../reducers';
import {
  CloseSideNavAction,
  OpenSidenavAction,
  ResizeWindowAction
} from '../../actions/layout.actions';
import { NavItem } from '../../models/nav-item';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
  @HostListener('window:resize', ['$event'])
  onWindowResize(event: any) {
    this.store.dispatch(new ResizeWindowAction({
      width: event.target.innerWidth,
      height: event.target.innerHeight
    }));
  }
  showSidenav: Observable<boolean>;
  sidenavMode: Observable<string>;
  viewList: Array<NavItem>;
  isOpen: boolean;
  mode: string;

  constructor(private translate: TranslateService,
              private store: Store<fromRoot.State>) {
    this.showSidenav = this.store.select(fromRoot.getShowSidenav);
    this.sidenavMode = this.store.select(fromRoot.getSidenavMode);
  }

  ngOnInit() {
    this.store.select(fromRoot.getShowSidenav)
        .subscribe(isOpen => {
          this.isOpen = isOpen;
        });
    this.store.select(fromRoot.getSidenavMode)
        .subscribe(mode => {
          this.mode = mode;
        });
    this.store.select(fromRoot.getViewList)
        .subscribe(views => {
          this.viewList = views
        });
    this.translate.addLangs(['en', 'sk']);
    this.translate.setDefaultLang('en');
    const browserLang = this.translate.getBrowserLang();
    this.translate.use(browserLang.match(/en|sk/) ? browserLang : 'en');
  }

  onToggleSidenav(): void {
    if (this.isOpen) {
      this.store.dispatch(new CloseSideNavAction());
    } else {
      this.store.dispatch(new OpenSidenavAction());
    }
  }

  onSidenavClosed(): void {
    this.store.dispatch(new CloseSideNavAction());
  }

  closeIfSmall(): void {
    if (this.mode === 'over') {
      this.store.dispatch(new CloseSideNavAction());
    }
  }
}
<app-sidenav [showSidenav]="showSidenav | async"
             [sidenavMode]="sidenavMode | async"
             (sideNavClosed)="onSidenavClosed()">
  <app-nav-item *ngFor="let navItem of viewList"
                [navItem] = navItem
                (activate)="closeIfSmall()">
    {{ navItem.title  }}
  </app-nav-item>
  <app-toolbar (openMenu)="onToggleSidenav()"
               [tooltipMsg]="'toolbar.sideMenuTooltipMsg' | translate">
    {{ 'app.title' | translate }}
  </app-toolbar>
  <div class="app-content">
    <router-outlet></router-outlet>
  </div>
</app-sidenav>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""