Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
Use defined value in module provider in other Angular module

I would like use provider value defined in other module. Here is example:

app.module.ts

...

import { ThemeModule } from '../shared/modules/theme/theme.module';

...

@NgModule({

  declarations: [
    RootComponent,
    LoginScreenComponent,
  ],

  imports: [
    BrowserModule.withServerTransition({ appId: 'serverApp' }),
    BrowserAnimationsModule,
    AppRoutingModule,
    ConfigModule,
    ThemeModule,
    ....
  ],

  providers: [
    ...
    { provider: "THEME_NAME", useValue: "VALUE" },
  ],
 
  bootstrap: [RootComponent]
})
export class MDMToolModule {}

theme.module.ts

import { NgModule } from '@angular/core';
import { ThemeService } from './services/ThemeService';

@NgModule({
    imports: [],
    declarations: [],
    providers: [
        {provide: "ThemeService", useFactory: (THEME_NAME) => {
            return new ThemeService(THEME_NAME)
        }},
    ],
    exports: []
})
export class ThemeModule {}

Is there possibility to pass VALUE defied not in module like above example (THEME NAME)?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

if you're providing value in root module then it will be available to all other modules too so you can then simply ask for that value using Inject decorator like this:

@Injectable()
export class ThemeService {
  constructor(@Inject("THEME_NAME") theme: string) {}
}

otherwise you can import your MDMToolModule inside ThemeModule though judging by the code you provided I'm assuming this MDMToolModule is your root module, you can also use Injection Token to avoid using those magic strings like this:

const ThemeName = new InjectionToken("token to inject theme name");

and then use it inside theme.module.ts

@NgModule({
  providers: [
    { provide: ThemeName, useValue: "DarkKnight" },
    ThemeService
  ]
})
export class ThemeModule {}

theme.service.ts

@Injectable()
export class ThemeService {
  constructor(@Inject(ThemeName) theme: string) {}
}
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda