angular/packages/core/schematics/migrations/provide-initializer
Younes Jaaidi 1fe001e18b fix(migrations): fix provide-initializer migration when using useFactory (#58518)
Priori to this commit, initializer functions with dependencies were not migrated correctly.
With this commit, the function is executed in a injection context to allow the usage of `inject`.

PR Close #58518
2024-11-21 20:59:35 +00:00
..
BUILD.bazel feat(core): add syntactic sugar for initializers (#53152) 2024-10-22 09:38:18 -07:00
index.ts feat(core): add syntactic sugar for initializers (#53152) 2024-10-22 09:38:18 -07:00
README.md feat(core): add syntactic sugar for initializers (#53152) 2024-10-22 09:38:18 -07:00
utils.ts fix(migrations): fix provide-initializer migration when using useFactory (#58518) 2024-11-21 20:59:35 +00:00

Replace APP_INITIALIZER, ENVIRONMENT_INITIALIZER, and PLATFORM_INITIALIZER with provider functions

Replaces APP_INITIALIZER, ENVIRONMENT_INITIALIZER, and PLATFORM_INITIALIZER with their respective provider functions: provideAppInitializer, provideEnvironmentInitializer, and providePlatformInitializer.

Before

import {APP_INITIALIZER} from '@angular/core';

const providers = [
  {
    provide: APP_INITIALIZER,
    useValue: () => { console.log('hello'); },
    multi: true,
  }
];

After

import {provideAppInitializer} from '@angular/core';

const providers = [provideAppInitializer(() => { console.log('hello'); })];