angular - 如何在 Angular 应用程序开始时设置 ABP 显示语言?
问题描述
我正在开发一个作为 MVC UI 项目开始的项目。但是,我们决定将 Angular 用于应用程序的一小部分。我能够让它与不同的 ABP 服务一起工作;但是,我目前坚持尝试在 Angular 应用程序启动时设置本地化服务使用的语言,以便它与用户在应用程序的 MVC 部分中配置的语言相同。
我们使用的是 ABP 3.0.5 版。
我的想法是使用 Web 服务获取用户在 ASP.NET 端选择的语言,然后使用SetLanguage
. 使用默认 Angular 模板中的语言选择代码,我想出了这样的东西:
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent implements OnInit {
title = 'MyAngularApp';
constructor(
private userInfo: UserInfoService,
private store: Store) { }
ngOnInit(): void {
this.userInfo.getLanguage().subscribe(result => {
this.store.dispatch(new SetLanguage(result));
});
}
}
在这段代码中,该getLanguage
函数工作并返回正确的语言代码(en
例如)。但是,似乎调用this.store.dispatch(new SetLanguage(result))
与角度路由器混淆并将我的路由重置为其当前值。例如,如果我想导航到https://localhost:12345/angularApp/?val=00112233
更改语言会导致应用程序被重定向到https://localhost:12345/angularApp/
.
我是否使用了正确的方法来初始化应用程序语言?你会为这样的任务推荐什么?
解决方案
推荐阅读
- apache-spark - Apache Spark Partitioning Data Using a SQL Function nTile
- api - OpenAPI 与 JSON:API
- r - 用 r 中的另一个数据替换列表中的每一行
- java - java构建过程中生成源是什么意思
- javascript - JavaScript,在异步函数中返回函数回调
- java - 无法转换为 class 。. . 是 loader 的未命名模块
- ghost-blog - 如何解决错误 503 Service Unavailable (Ghost)
- c# - ASP.NET Core 使用自定义 HttpClientHandler 模拟 HttpClient
- reactjs - 使用多个(最新)第 3 方反应库反应“未捕获的不变违规:元素类型无效”
- python - 尼泊尔数字的 Python 正则表达式