How to provide ngmodule level providers to converted standalone components

145 views Asked by At

We have a VERY specific and hard-to-understand ngModule system in place because of such heavy dependency pool and because of circular dependencies. I ran the standalone schematic on our entire app and converted every single component/pipe/directive to standalone with the 16 upgrade.

Here is an example of our old auth module, and as you can see there is an AuthService provided at that level to the 3 components:

@NgModule({
  declarations: [HandleAuthComponent, LoginComponent, LogoutComponent],
  imports: [CommonModule, AppMaterialModule, MatCardModule],
  providers: [AuthService],
})
export class AuthModule {}

Now that the application converted those 3 components to standalone, is there any way to provide a service at the MODULE leve like before, or should I NOT have converted those components to standalone since they have module level providers? (Refactoring services to be either root or component level is not something I can do right now)....

@NgModule({
  imports: [HandleAuthComponent, LoginComponent, LogoutComponent],
  providers: [AuthService],
})
export class AuthModule {}

Can I import those 3 componednts into the old module instead of declaring them, and provide that AuthService at the same level as before they were standalone to make sure the scope of that AuthService is like it was before standalone?

0

There are 0 answers