【发布时间】:2022-11-24 23:56:23
【问题描述】:
我有一个如下所示的全局配置文件:
{
"options": {
"pages": 5,
"paginator": true,
"rows": [
"5",
"10",
"15",
"20",
"25",
"30",
"40",
"50",
"100"
],
"perPage": 10,
"sorting": true,
"selection": true
}
}
我通过ngOnit() 中的服务调用此文件,如下所示:
ngOnInit() {
this.getGlobalSettings();
}
getGlobalSettings(){
const providerSubscription = this.leaveApplicationService.getGlobalSettings().subscribe(res => {
this.pageSettings = res;
},
error => {
console.log(error);
},
() => {
});
this.subscriptionCollection.add(providerSubscription);
}
我在 HTML 文件中使用这些设置,但似乎配置仅在视图初始化后才加载。因此,当我尝试在视图中访问 pageSettings.options 时会抛出错误。
如何解决这个问题并在应用程序初始化后立即加载设置,以便它可用于所有组件?
【问题讨论】:
-
您的 leaveApplicationService 是如何提供的?您也可以分享 Service + getGlobalSettings() 方法的代码吗?
标签: angular typescript