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

199
Vistas
How one service (not singleton) can be used by one directive and one component?

I have created a directive that is using component as its template. Both of them use the same service included in providers:

@Component({
  selector: 'my-component',
  providers: [MyService],
  ..
}

@Directive({
  selector: '[myDirective]',
  providers: [MyService]
})

Now here is the problem. They use the same service, but while one is changing the server, the directive that has been register to its change didn't got the change at all:

this.myService.dataUpdated.subscribe
      (
        (data: someObject) => {
          // Do something...
        }
      )

Seems to me they are not using the same service at all.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I don't see a reason why singleton should not be used for your scenario. It seems to me that singleton should be used on your case, that's why you don't see the changes at all.

Try to provide your service in your NgModule like this

 @NgModule({
  ...
  providers: [MyService]
  ...

Hope this helps.

over 4 years ago · Santiago Trujillo 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