moved header to its own component

This commit is contained in:
Art Lowel
2016-12-12 13:36:02 +01:00
parent 9bbb947987
commit 9aa74b863e
6 changed files with 92 additions and 64 deletions

View File

@@ -1,7 +1,12 @@
import { Component, HostListener, Input, ChangeDetectionStrategy, ViewEncapsulation, OnDestroy, OnInit } from '@angular/core';
import { Event, NavigationEnd, Router } from '@angular/router';
import { TranslateService } from 'ng2-translate';
import {
Component,
ChangeDetectionStrategy,
ViewEncapsulation,
OnDestroy,
OnInit
} from "@angular/core";
import { Router } from "@angular/router";
import { TranslateService } from "ng2-translate";
@Component({
changeDetection: ChangeDetectionStrategy.Default,
@@ -11,14 +16,6 @@ import { TranslateService } from 'ng2-translate';
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnDestroy, OnInit {
// TODO: move header and all related properties into its own component
private navCollapsed: boolean;
private routerSubscription: any;
private translateSubscription: any;
example: string;
@@ -26,56 +23,28 @@ export class AppComponent implements OnDestroy, OnInit {
data: any = {
greeting: 'Hello',
recipient: 'World'
}
};
constructor(public translate: TranslateService, private router: Router) {
constructor(
private translate: TranslateService,
private router: Router
) {
// this language will be used as a fallback when a translation isn't found in the current language
translate.setDefaultLang('en');
// the lang to use, if the lang isn't available, it will use the current loader to get them
translate.use('en');
this.collapse();
}
ngOnInit() {
this.routerSubscription = this.router.events.subscribe((event: Event) => {
if (event instanceof NavigationEnd) {
this.collapse();
}
});
this.translateSubscription = this.translate.get('example.with.data', { greeting: 'Hello', recipient: 'DSpace' }).subscribe((translation: string) => {
this.example = translation;
});
}
ngOnDestroy() {
if (this.routerSubscription) {
this.routerSubscription.unsubscribe();
}
if (this.translateSubscription) {
this.translateSubscription.unsubscribe();
}
}
@HostListener('window:resize', ['$event'])
private onResize(event): void {
this.collapse();
}
private collapse(): void {
this.navCollapsed = true;
}
private expand(): void {
this.navCollapsed = false;
}
public toggle(): void {
this.navCollapsed ? this.expand() : this.collapse();
}
public isNavBarCollaped(): boolean {
return this.navCollapsed;
}
}