- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
什么相当于the APP_INITIALIZER
Angular 中的功能模块?我想在(延迟)加载我的功能模块时运行一些代码。该代码需要注入(inject)一些依赖项。
不过我似乎找不到任何类似的模块项目。我在 Angular 文档网站(“initializer”)上使用了搜索,但一无所获。我浏览了部分模块文档并在浏览器中使用了类似的搜索词。但我还没有找到任何东西。
如何在 Angular 中加载模块时运行代码(取决于通过 DI 的共享服务)?
附言。可能这是一个 XY 问题,其中“Y”是我上面的问题。在这一点上,我本质上对了解“Y”很感兴趣,但为了完整起见,我的“X”是我希望我的功能模块回调到共享模块中的 MenuService
以注册任何功能模块想要贡献的菜单项。
最佳答案
不确定它是否符合习惯,但我会通过建议为此目的使用模块 constructor
函数来回答我的问题。例如:
@NgModule({
imports: [
CommonModule,
ThingsRoutingModule,
],
declarations: [
// Feature module components here
],
})
export class ThingsModule {
constructor(myService: MySharedService) {
myService.doSomething('From lazy loaded feature module!');
}
}
MySharedService
被注入(inject)的地方。
关于angular - 相当于 Angular 中 APP_INITIALIZER 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51191231/
我有一个简单的配置服务,我在我的 app.shared.module.ts 中使用 APP_INITIALIZER token 连接: ConfigService, {
我正在尝试使用 auth0/auth0-angular Angular 11 应用程序中的库。 我正在关注 loading config dynamically 上的部分. 它提供了这个示例应用模块代
我有一个延迟加载的模块,我正在尝试添加 APP_INITIALIZER 但它没有触发。我的语法与我的主应用程序完全相同,它按预期工作。延迟加载的模块是否会触发 APP_INITIALIZER? 最佳答
我正在使用 APP_INITIALIZER Hook 从本地 json 文件加载一些应用配置。加载配置后,我想在另一个提供程序中使用它(为我生成的 swagger-codegen 服务设置 BASE_
我有一个 Angular (v6.0.0) 应用程序,我正试图通过在 APP_INITIALIZER 期间引入运行时配置来设置它。我已经阅读了几篇文章(例如 this 和 this 和 this )以
我正在使用 APP_INITIALIZER 加载环境特定变量。我需要在我的 authConfigFactory 中使用这些变量,但工厂会在 APP_INITIALIZER 完成应用程序配置之前继续加载
我正在使用这个 gist在应用程序启动期间读取配置文件。这工作正常,但在进行单元测试时出现错误 Cannot read property 'SomeProperty' of null。 我也添加了pr
我正在使用 this 中推荐的 APP_INITIALIZER回答,我的服务返回一个 promise ,但它并不总是等待它解决,我可以看到我的组件 console.logging 未定义,然后服务记录
我有一个 Angular 5.2.0 应用程序。我查找了如何实现 APP_INITIALIZER在应用程序启动之前加载配置信息。这里是 app.module 的摘录: providers: [
typescript :2.2.0 Angular :4.0 我试图通过使用 APP_INITIALIZER 确保在应用程序启动之前初始化 ConfigService 对象。我发现了很多关于如何执行此
在我的 Angular 6 应用程序中,我通过这样的 Http 服务加载我的外部化配置: export function getSettings(appLoadService: ConfigLoadS
问题是:我需要进行 http 调用并存储生成动态路由所需的对象。所以,我正在利用 APP_INITIALIZER。 // app.module.ts import { ApplicationServi
我在使用 Angular APP_INITIALIZER 加载配置文件时遇到问题。 它似乎服务开始加载 APP_INTIALIZER,因此配置文件无法到达服务, 并且在配置文件需要在服务启动之前进行设
如何在 Angular 应用程序执行 app_initializer 代码时显示等待指示器。 截至目前,我可以在加载应用程序之前显示等待指示器。但是在该页面保持空白直到 app_initializer
背景:我需要在应用程序启动期间执行几次初步检查(1)从./assets/config.json文件读取angular应用程序配置并从那里获取API端点,(2)进行API调用到端点在第一步中检索并从后端
类似于Angular 5 APP_INITIALIZER gives Cyclic dependency error 我有一个使用 Angular 5 和 SSR 的应用程序,我刚刚从 Angular
我有一个来自静态 AppConfigService 的配置文件的值。 说明如下: 引用代码/文章:https://blogs.msdn.microsoft.com/premier_developer/
我在使用 Angular 4 时遇到了一些引导问题。我有一个配置文件 (json),我在应用程序启动时从服务器加载它(另请参见 here )。这到目前为止有效。 现在我有一个 dependency这需
我正在寻找能让我在某个模块初始化时执行代码的东西。这个模块在我的应用程序中是延迟加载的。 APP_INITIALIZER 仅适用于应用程序初始化过程(一次从引导的主模块开始)。 我不能使用延迟加载模块
我正在尝试一个简单的 APP_INITIALIZER使用我的 angular 应用程序,但出现错误 this.appInits[i] is not a function - 无法弄清楚问题。 这是我的
我是一名优秀的程序员,十分优秀!