[英]How to call a method inside a service from app.module in angular and use the values in Imports
I'm moving all the environment related data from angular to external api call so that it can be build once and deployed in multiple environments.我正在将所有与环境相关的数据从 angular 移动到外部 api 调用,以便它可以构建一次并部署在多个环境中。 For NGX Logger it is imported in
app.module.ts
and the configs for level
and serverLogLevel
is fetched from environment.ts
currently since it varies based on evironments.对于 NGX Logger,它是在
app.module.ts
中导入的,而level
和serverLogLevel
的配置目前是从environment.ts
中获取的,因为它根据环境而有所不同。
This is the current NGXLogger config这是当前的 NGXLogger 配置
imports:[
LoggerModule.forRoot({
level: NgxLoggerLevel[env.consolelvl],
serverLogLevel: NgxLogerLevel[env.serverlvl]
})
]
I want these env variables to be fetched from api call.我希望从 api 调用中获取这些环境变量。 How can this be achieved.
这怎么可能实现。
You can set a default value for your levels您可以为级别设置默认值
And later on when you execute your API call you can update the logger config with partialUpdateConfig
稍后当您执行 API 调用时,您可以使用
partialUpdateConfig
更新记录器配置
Attention, this means the logs called before your API call will use the default level注意,这意味着在您调用 API 之前调用的日志将使用默认级别
PS: This requires 5.0.11, if you have an older version you need to use updateConfig
PS:这个需要5.0.11,如果你有旧版本需要使用
updateConfig
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.