0

I'm on angular version 15.2.4 and decided to use the migration tool to convert my components to standalone compoonents.

The issue I'm having is when I run the command: ng g @angular/core:standalone

I never get the option to select any of the modes that are suggested here in the migration modes: https://angular.io/guide/standalone-migration#migration-modes

It seems to run fine and the app still works with no issues but when I run the tests I get a lot of these type of errors and tests failing:

NullInjectorError: R3InjectorError(DynamicTestModule)[ActivatedRoute -> ActivatedRoute]:

NullInjectorError: No provider for ActivatedRoute!

Any input on this would be greatly appreciated.

tercou1
  • 113
  • 2
  • 11
  • 1
    Some of the Modules: Animation, RouterModules, HttpClient.. not import as Modules, else add in providers, see, e.g. this [SO](https://stackoverflow.com/questions/75403140/how-to-use-animations-in-an-angular-standalone-component/75403773#75403773) or [this one](https://stackoverflow.com/questions/76719041/error-cant-bind-to-routerlink-since-it-isnt-a-known-property-of-a-with-s/76719949#76719949) – Eliseo Jul 21 '23 at 09:32

1 Answers1

0

It might help somebody else, the solution to my issue was (with the help of @Eliseo comment) to go to the bottom of main.ts and add in the providers that I was using in my app.module.ts file, like this:

//main.ts file
bootstrapApplication(AppComponent, {
  providers: [
    xxxService,
    xxxService,
    AppConfig,
    xxxConfig,
    {
      provide: SESSION_STORAGE_CONFIG,
      useValue: {
        namespace: "xxxx",
      },
    },
    {provide: ErrorHandler, useClass: GlobalErrorHandler},
    {
      provide: HTTP_INTERCEPTORS,
      useClass: ServerErrorInterceptor,
      multi: true,
    },
    importProvidersFrom(
      xxxModule.forRoot(),
    ),
  ]
}).then()
tercou1
  • 113
  • 2
  • 11