使用APP_INITIALIZER实现Angular运行时环境变量配置
                        程序开发
                        2023-09-19 19:32:47 
                    
                    创建一个angular空项目
ng new angular-runtime-config 因为是demo 这里就不选择路由了,css我使用scss

创建一个名为config的service文件
cd angular-runtime-config
 ng g service config 对config.service.ts文件 增加两个方法和一个私有属性

在app.module.ts文件中增加如下设置

启动服务查看一下结果
ng serve --o 你可以通过在app.compontent.ts中添加console.log来判断一下是否appConfig早于app.component执行
现在我们在app.compontent.ts中试着调用ConfigService中的getConfig方法看一下是否能获取到值


github源码 https://github.com/lilugirl/angular-runtime-config
转载于:https://my.oschina.net/lilugirl2005/blog/3086483
标签:
                            上一篇:
                             angular-cli 无法启动项目
                                                        下一篇:
                                                    
                        相关文章
- 
                    			无相关信息                            
 
