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 ^^
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();
}
}