我目前有一个切换开关,可以将文本翻译成不同的语言(即英语到普通话,反之亦然)。在我的选择标签中,每次单击切换开关时,我都希望选项文本在英语和普通话之间切换。我注意到只有在第一次填充选项或重新加载选项值时才会发生转换。我如何实现每次切换开关时都会翻译选项描述文本?
<select class="chosen-select" id="mode">
<option></option>
<option *ngIf="modeList.length === 0" disabled tabindex="-1">Please select first</option>
<option *ngFor="let mode of modeList" [value]="mode.code">
{{mode.code}}: {{mode.description | translate}}
</option>
</select>
我也尝试在
ngOnInit()
中添加onLangChange希望它能检测到但仍然失败。
this.translate.onLangChange.subscribe((event: LangChangeEvent) => {
this.langUsed = event.lang;
});