简体   繁体   中英

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. 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.

This is the current NGXLogger config

imports:[
LoggerModule.forRoot({
level: NgxLoggerLevel[env.consolelvl],
serverLogLevel: NgxLogerLevel[env.serverlvl]
})
]

I want these env variables to be fetched from api call. 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

Attention, this means the logs called before your API call will use the default level

PS: This requires 5.0.11, if you have an older version you need to use updateConfig

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM