This is project reproduces this issue: storybookjs/storybook#22674
These steps demonstrate APP_INITIALIZER
not running in Storybook.
- Install and start Storybook:
yarn && yarn storybook
- Open Storybook in a browser.
- Open console in web developer tools.
- Note that
Hello from useFactory
is not logged.
These steps demonstrate APP_INITIALIZER
running as expected outside Storybook.
- Install Angular CLI (version 16 or later)
- Create a new app:
ng new --standalone
- Update
app.config.ts
as shown below. - Open the application in a browser.
- Open console in web developoer tools.
- Note that
Hello from useFactory
is logged.
// app.config.ts
import { APP_INITIALIZER, ApplicationConfig } from '@angular/core';
export const appConfig: ApplicationConfig = {
providers: [
{
provide: APP_INITIALIZER,
useFactory: () => () => {
console.log('Hello from useFactory');
},
multi: true,
},
],
};