Within a form creation component, I have multiple functions that need to be executed simultaneously. Each function corresponds to a dropdown field option such as gender, countries, and interests which are all fetched from the server. Currently, I call these functions individually in the ngOnInit lifecycle hook and it works correctly. However, I am curious if there is a more efficient way to execute these functions concurrently?
ngOnInit() {
this.gender();
this.countries();
this.interests();
}
gender() {
this.apiService.gender().subscribe((res: any) => {
this.gender = res;
}, error => {
console.log(error);
});
}
countries() {
this.apiService.countries().subscribe((res: any) => {
this.countries = res;
}, error => {
console.log(error);
});
}
interests() {
this.apiService.interests().subscribe((res: any) => {
this.countries = res;
}, error => {
console.log(error);
});
}