From bb4e3e51c0b3f8024b4ec1703f1b69842eb777e3 Mon Sep 17 00:00:00 2001 From: Joachim Nielandt Date: Sun, 25 Mar 2018 10:59:15 +0200 Subject: [PATCH] Language switch is working. --- .../languagetoggle.component.ts | 22 ++++++++++++++----- src/app/components/root/root.component.ts | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/app/components/languagetoggle/languagetoggle.component.ts b/src/app/components/languagetoggle/languagetoggle.component.ts index 61b4c0c..7c3bfa7 100644 --- a/src/app/components/languagetoggle/languagetoggle.component.ts +++ b/src/app/components/languagetoggle/languagetoggle.component.ts @@ -26,19 +26,29 @@ export class LanguagetoggleComponent implements OnInit { ngOnInit() { this.stateService.getLanguageFromRoute(this.route).subscribe(lang => { - console.log('languagetoggle gets this language: ' + lang); - console.log('(' + this.language + ')') + if(lang==null) { + console.log('language is null from first level route, ignoring'); + return; + } + console.log('languagetoggle gets first level lang: '+lang); if (lang === this.language) { - console.log('equalled (first level of route)! showing the component'); + console.log('equalled (first level of route)! showing the component' + this.language); this.show = true; + } else { + this.show = false; } }); this.stateService.getLanguageFromRoute(this.route.parent).subscribe(lang => { - console.log('languagetoggle gets this language from parent: ' + lang); - console.log('(' + this.language + ')') + if(lang==null) { + console.log('language is null from parent level route, ignoring'); + return; + } + console.log('languagetoggle gets parent level lang: '+lang); if (lang === this.language) { - console.log('equalled (parent level of route)! showing the component'); + console.log('equalled (parent level of route)! showing the component ' + this.language); this.show = true; + } else { + this.show = false; } }); } diff --git a/src/app/components/root/root.component.ts b/src/app/components/root/root.component.ts index 472fe56..a00456f 100644 --- a/src/app/components/root/root.component.ts +++ b/src/app/components/root/root.component.ts @@ -23,7 +23,7 @@ export class RootComponent implements OnInit { console.log('oninit of root component'); this.route.paramMap.subscribe(val => console.log(val)); - this.stateService.getLanguageFromRoute(this.route).subscribe(val => {console.log('ngoninit root' + val)}); + this.stateService.getLanguageFromRoute(this.route).subscribe(val => {console.log('ngoninit root language: ' + val)}); this.pageType$ = this.stateService.getLanguageFromRoute(this.route).map(language => { if (this.router.url.endsWith('posts')) {