#Migrate NgModule with constructor to standalone

1 messages · Page 1 of 1 (latest)

regal geode
#

Hello, what is the best option to migrate NgModule with constructor(), to standalone? For example how to rewrite the following code to standalone?

@NgModule({
  imports: [
    // ...
    MatIconModule
  ]
})
export class AppModule {
  constructor(matIconRegistry: MatIconRegistry, domSanitizer: DomSanitizer){
    matIconRegistry.addSvgIconSet(
      domSanitizer.bypassSecurityTrustResourceUrl('./assets/mdi.svg')
    );
  }
}

I see two options:

  1. Use APP_INITIALIZER (possible app start slowdown).
  2. Move this code to root component constructor.
    But what will be preferred?
hidden ore
#

I would put it in the app component. The goal of APP_INITIALIZER is precisely to delay the startup of the app until something async has finished, but this is synchronous code. So it doesn't need to be there.

regal geode
#

I agree. I couldn't find a better place, than app.component for stuff like this (one-time initializers). Thanks for confirmation.

blazing crater
hidden ore