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

200
Vistas
Angular - I want to split a service into several services but share the same data

I have a service that is 1000 lines long, I would like to split it into several services but I need to share some data between these different services.

@Injectable()
export class ServiceParent {
  toto = new Toto(),
}

@Injectable()
export class ServiceChild extend ServiceParent {

  init() {
    this.toto.doSomething();
  }
}

@Component()
export class myComponent {

  ngOnInit() {
    console.log('this.ServiceChild.init()') // return undefined
  }
}

How to solve this problem ?

Thanks ^^

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Simply create a global variable.

let toto = new Toto();

@Injectable()
export class Service1 {

  init() {
    this.toto.doSomething();
  }
}


@Injectable()
export class Service2 {

  init() {
    this.toto.doSomething();
  }
}
about 4 years ago · Juan Pablo Isaza 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