Having a service function that needs to be called
private callService() {
this.functionOne();
this.functionTwo();
this.functionThree();
}
private getOtherInfo() {
// pure sync here
this.getId(this.user['data']);
this.getType(this.name['data']);
}
The aim is to run callService
first and then getOtherInfo
, but encountering issues reaching the second function.
The functions within callService
are structured as below:
private functionOne() {
this.user['loading'] = true;
this.service['user'].get().subscribe(data => {
this.user['data'] = data;
}
}
private functionTwo() {
this.name['loading'] = true;
this.service['name'].get().subscribe(data => {
this.name['data'] = data;
}
}
.....
To address the problem, I modified the function like so:
private callService(): Promise<any> {
return Promise.resolve() => {
this.functionOne();
this.functionTwo();
this.functionThree();
});
}
Within ngOnInit()
the following logic is implemented:
this.callService().then(()=> this.getOtherInfo());
Despite these changes, the second function remains unreachable.