Several angular application initializers

We know that in the root module we can install APP_INITIALIZERwhich loads some dependencies into the backend and then loads the first component

{
    provide: APP_INITIALIZER,
    useFactory: configLoader,
    multi: true,
    deps: [ConfigService]
}

I will load my custom configs before the application starts above, but I want to do something else, for example, plug in a websocket before launching my application.

I know that I can use the function configLoaderthat I wrote that first loads the configs and then connects the websocket in this configLoader function, but for some reason I cannot do it right now, so I need to do something like this:

{
    provide: APP_INITIALIZER,
    useFactory: [configLoader, websocketLoader],
    multi: true,
    deps: [ConfigService, WebsocketService]
}

But unfortunately, this will not work. So, is there a way to load multiple application initializers?

+4
1

useFactory

{
    provide: APP_INITIALIZER,
    useFactory: websocketLoader,
    multi: true,
    deps: [ConfigService, WebsocketService]
},
{
    provide: APP_INITIALIZER,
    useFactory: configLoader,
    multi: true,
    deps: [ConfigService, WebsocketService]
}

multi: true (APP_INITIALIZER) ( multi: false), DI .

+5

Source: https://habr.com/ru/post/1682913/


All Articles