Created
September 21, 2017 14:05
-
-
Save Tuizi/311cff5e34495c1ec02678ca72ff1337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<header> | |
<button (click)="lang.next('fr')">FR</button> | |
<button (click)="lang.next('en')">EN</button> | |
</header> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component({ | |
selector: 'i-app', | |
templateUrl: './app.component.html', | |
styleUrls: ['./app.component.scss'], | |
}) | |
export class AppComponent implements OnInit { | |
lang = new Subject<string>(); | |
lang$: Observable<string>; | |
constructor(private readonly translate: TranslateService, | |
private readonly store: Store<fromRoot.State>) { | |
this.translate.setDefaultLang('en'); | |
this.lang$ = this.store.select(fromRoot.getCurrentLanguage); | |
} | |
ngOnInit() { | |
this.lang | |
.startWith(this.translate.getBrowserLang()) | |
.subscribe(lang => this.store.dispatch(new language.Set(lang))); | |
this.lang$.subscribe(lang => this.translate.use(lang)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment