Incorporating APP_INITIALIZER into my app has been a bit of a challenge. In the app.module.ts file, I have configured it with all the necessary imports like so:
@NgModule({
...
providers: [ ..., ContextService, { provide: APP_INITIALIZER, useFactory: (context: ContextService) => () => context.load(), deps: [ContextService], multi: true } ],
...
})
Interestingly, when I do a fresh build (ng build -watch), I encounter the following error, but strangely, subsequent builds work without any issues.
ERROR in Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 24:46 in the original .ts file), resolving symbol AppModule in C:/.../app.module.ts
To resolve this initial build error, I attempted moving () => context.load()
into an exported function within the same file:
export function loadContext(context: ContextService) {
return () => context.load();
}
After that, I adjusted the providers section of @NgModule to reference this new function:
@NgModule({
...
providers: [ ..., ContextService, { provide: APP_INITIALIZER, useFactory: (context: ContextService) => loadContext(context), deps: [ContextService], multi: true } ],
...
})
Despite these changes, the initial build still fails with the same error as mentioned above. Any suggestions on how to tackle this initial build error would be greatly appreciated.