homepage/src/app/components/languagetoggle/languagetoggle.component.ts
2018-03-25 10:49:54 +02:00

47 lines
1.5 KiB
TypeScript

import {Component, Input, OnInit} from '@angular/core';
import {ActivatedRoute} from '@angular/router';
import {StateService} from '../../services/state.service';
@Component({
selector: 'app-languagetoggle',
templateUrl: './languagetoggle.component.html',
styleUrls: ['./languagetoggle.component.scss']
})
export class LanguagetoggleComponent implements OnInit {
/**
* This is the language for which the component is defined. Typically, when the currently set language is equal to this variable,
* the component will be visible.
*/
@Input()
private language: string;
/**
* if this is set to true, the component will be visible
*/
private show = false;
constructor(private route: ActivatedRoute, private stateService: StateService) {
}
ngOnInit() {
this.stateService.getLanguageFromRoute(this.route).subscribe(lang => {
console.log('languagetoggle gets this language: ' + lang);
console.log('(' + this.language + ')')
if (lang === this.language) {
console.log('equalled (first level of route)! showing the component');
this.show = true;
}
});
this.stateService.getLanguageFromRoute(this.route.parent).subscribe(lang => {
console.log('languagetoggle gets this language from parent: ' + lang);
console.log('(' + this.language + ')')
if (lang === this.language) {
console.log('equalled (parent level of route)! showing the component');
this.show = true;
}
});
}
}