在angular.json的构建配置中将i18n-locale设置为像希伯来语这样的RTL语言,不会将html的dir属性更改为RTL。是否有另一种方法可以根据语言环境自动设置html或主体dir
属性?
答案 0 :(得分:1)
AppComponent应该听以下语言更改:
app.component.ts
@Component(...)
export class AppComponent {
public dir: string;
constructor(private translate: TranslateService) {
translate.onLangChange.subscribe(x => this.dir = x == "en" ? "ltr" : "rtl")
}
}
app.component.html:
<div [dir]="dir">
<router-outlet></router-outlet>
</div>