gpt4 book ai didi

angular - 相当于 Angular 中 APP_INITIALIZER 的模块

转载 作者:行者123 更新时间:2023-12-05 04:05:26 24 4
gpt4 key购买 nike

什么相当于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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com