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);
}
}
在模板中我有这个链接
<a [routerLink]="['en']">test</a>
如何将值从 ngOnInit 传递到该 routeLink?例如我想要这样的东西:
<a [routerLink]="[(lang)]">test</a>
但它是未定义的。在 ngOnInit 中它具有价值