Skip to content

Instantly share code, notes, and snippets.

@Tuizi
Created September 21, 2017 14:05
Show Gist options
  • Save Tuizi/311cff5e34495c1ec02678ca72ff1337 to your computer and use it in GitHub Desktop.
Save Tuizi/311cff5e34495c1ec02678ca72ff1337 to your computer and use it in GitHub Desktop.
<header>
<button (click)="lang.next('fr')">FR</button>
<button (click)="lang.next('en')">EN</button>
</header>
@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