Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!