export class AppComponent implements OnInit {
sub: any;
lang: string;
constructor(public translate: TranslateService, public route: ActivatedRoute, private languageService: LanguageService) { }
ngOnInit() {
this.sub = this.route.params.subscribe(p => {
let lang = p['lang'];
this.lang = lang;
});
this.languageService.translate.use(this.lang);
}
}
and in template i have this link
<a [routerLink]="['en']">test</a>
How can I pass value from ngOnInit to that routeLink? for example I want something like this:
<a [routerLink]="[(lang)]">test</a>
but it's undefined. in ngOnInit it has value
If lang
really is not undefined you should just be able to do this in your template:
<a routerLink="{{lang}}">test</a>
or
<a [routerLink]="lang">test</a>
Check with console.log(lang)
in your ngOnInit, if it really is set, first.