Reputation: 71
Angular root services are initialized by the Angular injection framework. I want to know the time sequence for each of the root service. For example, will the following demo code throw the predefined error?
export class RootService1(){
private isInit= false;
constructor(){
isInit= true;
}
public isInit():boolean{
return this.isInit;
}
}
export class RootService2(){
constructor(private rootService1: RootService1){
if(!rootService1.isInit()){
throw Error('Fatal error: the RootService1 is not init');
}
}
}
Upvotes: 0
Views: 148
Reputation: 6579
For example, will the following demo code throw the predefined error?
No Angular services are created on demand. So while RootService2 is injecting RootService1. RootService1 is created before the instance of RootService2 is created.
Upvotes: 1